开发者

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>

开发者_如何学Python2)

<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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜