1. 程式人生 > >jquery迴圈取出父元素下的子元素,併為其賦樣式

jquery迴圈取出父元素下的子元素,併為其賦樣式

$("#working div").each(function () { //迴圈id為working下的div
    if($(this).attr('id') == id){ //如果div的id == 傳入的id則選中
        $("#"+id).attr("style","background-color:#f6f9fd;padding:20px 15px 6px 15px;");
    }
    else { //否則還原
        $("#"+$(this).attr('id')).attr("style","background-color:#fff;padding:20px 15px 6px 15px;");
    }
});

這裡的 $(this) == $("#working div")中的某一個