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; }); 

http://jsfiddle.net/hynab/


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -