Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get nearest parent [duplicate]

Possible Duplicate:
nearest ancestor node in jQuery

html:

<div class="post">
    <h2><a href="#" title="">Pellentesque</a></h2>
    <p><a href="#" title="" class="more">More</a></p>
</div>

jQuery

$('.more').bind("hover", function(){
    $(this).parent('.post').hide() ;                      
});

on hover (.more) i want to hide the post, but it does nothing if i use parents() instead it deletes ALL the .posts on the page

any help appreciated

like image 700
mononym Avatar asked Nov 17 '11 13:11

mononym


1 Answers

Try

$('.more').bind('hover',function()
{
    $(this).closest('.post').hide();
});

here is the working demo with single class.
here is the demo with multiple classes.

like image 120
Exception Avatar answered Sep 29 '22 08:09

Exception