I am currently trying to find the parent of a parent of an element. I have a link being clicked that is in a If you have any sort of id/class for the parent, you can use parents() but that will give you all parents up to the < body > unless you filter() or stop it some other way like Hope this helps someone :) It should work. You can also try $(this).parents(tag) , where tag is the tag you want to find. For example: Will find the closest tr "up the chain". Try wrapping the $(this).parent() into an jQuery object like $($(this).parent()) I often find the need to do this to make sure I have a valid jquery object. From there you should be able to get a hold of the parents parent, or using the prev() perhaps. You can do parent of a parent and it's very easy: etc. also try , and I\'d like to get the
$(this).parents('.myClass');
$(this).parents("tr:first")
var getParentNode = function(elem, level) {
level = level || 1;
for (var i = 0; i < level; i++) {
if (elem != null) {
elem = elem.parentNode;
}
}
return elem;
}
.closest()
is not always best option specially when you have same element construct.<div>
<div>
<div>
</div>
</div>
</div>
var parent = $('.myDiv').parent();
var parentParent = $(parent).parent();
var parentParentParent = $(parentParent).parent();
$(this).closest('div.classname').hide();