admin管理员组文章数量:1403468
I know that I have somewhere inside div on any depth ( maybe one or two or three, it changes over time ) with class="nested". How to find that element on any depth using JQuery ?
I tried like
var nest=$('#container_div').find('.nested');
but it doesn't work.
I know that I have somewhere inside div on any depth ( maybe one or two or three, it changes over time ) with class="nested". How to find that element on any depth using JQuery ?
I tried like
var nest=$('#container_div').find('.nested');
but it doesn't work.
-
2
Other than missing an apostrophe your code should work fine.
find()
will look for the element no matter how deep it is. – kapa Commented May 5, 2012 at 15:14 -
You're missing a quote. This works fine:
$('#container_div .nested')
(.find()
is not needed). – Rob W Commented May 5, 2012 at 15:15
3 Answers
Reset to default 4And another syntax for fun:
var nest = $( '.nested', '#container_div' );
I give jQuery a context of where to look for the .nested
class.
var nest=$('#container_div').find('.nested');
Maybe you forgot quote?
Nothing wrong with the other answer but:
var nest=$('#container_div .nested');
is more concise. Separating selectors with a space is the same as find
within a selector. If for some reason you wanted to limit to direct children only,
var nest=$('#container_div > .nested');
本文标签: javascriptHow to find element with class on any depth using JQueryStack Overflow
版权声明:本文标题:javascript - How to find element with class on any depth using JQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744382872a2603591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论