One of My Favorite Functions: closest

Sometimes we may have a generic function that could be triggered from a couple of different places. For example, let's say you have an unordered list with sortable li tags inside and clickable anchor tags that fire the same event to do whatever with the acted on list element. New with jQuery 1.3 is the closest function, which will find the closest element matching the selector, including self. That means that in the scenario defined above we can have a function that looks like this to handle the event. [js]function() { var element = $(this).closest("li"); ... }[/js] Pretty clean code and it will work as long as the event is triggered anywhere from the target li all the way down through any of its children. This function is very similar the the parents function that we all know and love. That, of course, will not include the starting element in the search though.