jQuery prevent selecting nested divs -
i have following html structure:
<div class="comment"> ... <div class="comment"> </div> ... </div> i need select parent element class "comment" main one, not nested ones.
the problem is, cant use this:
$("parent > .comment") because main given in variable.
you can use filter method:
$('div.comment').filter(function(){ return !$(this).parents('.comment').length; }); or:
$('div.comment').filter(function() { return !$(this.parentnode).closest('.comment').length; });
Comments
Post a Comment