In my javascript experience, I found that is a very common task \"searching the nearest ancestor of an element with some condition (tag name, class,...)\". Can the parents(
Adding to @nickf's answer:
jQuery 1.3 simplifyed this task with closest.
closest
Given a DOM:
You can do:
$('#d').closest("div"); // returns [ div#b ]
[Closest returns a] set of elements containing the closest parent element that matches the specified selector, the starting element included.