Pellentesque...">

Jquery get closest parent

Possible duplicate:
closest 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 message, but it does nothing if I use parent (), instead it removes ALL .posts on the page

any help appreciated

+6
source share
2 answers

Try

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

here is a working demo with one class.
here is a demo with several classes.

+9
source

Use jQuery.closest: http://api.jquery.com/closest/

+6
source

Source: https://habr.com/ru/post/901715/


All Articles