DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Find Ancestor Element Of A Tag Given An Object Reference
Retrieves the ancestor element of a tag given an object reference.
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com
function findAncestor(o, tag){
for(tag = tag.toLowerCase(); o = o.parentNode;)
if(o.tagName && o.tagName.toLowerCase() == tag)
return o;
return null;
}





