How to apply .each() only for certain parents?
$("table").each(function(){
//Code goes here
}
I want use this(above code ) for whose parents class attribute "featured". so from below example I want include only 1) ex. ex:
1)
<div class="featured">
<table>
</table>
</div>
<div class="Nonfeatured">
<table>
</table>
</div>
$(".featured > table").each(function(){
//Code goes here
}
I think you want
$(".featured table").each(function(){
//Code goes here
}
...which says, "for each table
element that is a descendant of an element with class "featured", run this function."
Or if you want it only for direct children of those elements:
$(".featured > table").each(function(){
//Code goes here
}
...which says, "for each table
element that is an immediate child of an element with class "featured", run this function."
More:
- Descendant selector
- Child selector
Try this:
$(".featured table").each(function(){
//Code goes here
}
精彩评论