jQuery Traversing Tips

Just a quick review of tips available in jQuery to manage nodes (contents) near by the content / node which is triggered an event like click, hover etc

Functions: find, parent, parents, children, first, last, closest

Suppose you need to manage some nodes nearby a link or a button on an event.



// code goes here


To get the current parent of triggered element, use $(this).parent()

To get the parent which has a class , use:


To find any other element just above the node, use :


to get the first element in find, use


and for last, use


To get exactly the child nodes, use:


Here comes another very useful function, which is, closest


Permanent link to this article: https://blog.openshell.in/2011/02/jquery-traversing-tips/

Leave a Reply

Your email address will not be published.