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');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744382872a4571516.html
评论列表(0条)