| Element.findParent = function( | element, | | selector | ) |
|
Attempts to finds a parent for a given element that matches a partial selector string. If the element itself matches the selector, it is returned instead. This can be particularly useful in mouse event handlers, where the element that fires the event tends to be the deepest element in the DOM, and you want to update a containing element.
Parameters
| element | Element, the base element to search from |
| selector | String, a partial selector to find a parent element (or the element itself if it matches). This is partial in the sense that it is a specific tagName with className, and/or ID only |
Example
function navItemOnMouseClick(event)
{
var element = Event.element(event);
var navItem = Element.findParent(element, "a.nav-item");
// now you can operate on the link, if for example there were span tags inside each link, which might be in "element"
}