//*** This code is copyright 2003 by Gavin Kistner, !@phrogz.net //*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt //*** Reuse or modification is free provided you abide by the terms of that license. //*** (Including the first two lines above in your source code satisfies the conditions.) //Given a reference to an HTML object, returns the first ancestor of that element which is of type 'elementType' //You may also supply a string for the third param, which must be found as an attribute or class of the ancestor //If no such node is found, returns null function FindAncestor(me, elementType, attributeOrClass) { if (!me || (!elementType && !attributeOrClass)) return null; while (me!=null){ if ( (elementType==null || me.tagName.toLowerCase()==elementType.toLowerCase()) && (attributeOrClass==null || me.getAttribute(attributeOrClass) || me.className.indexOf(attributeOrClass)!=-1) ) return me; me=me.parentNode; } return null; } //e.g. FindAncestor(event.srcElement,'table'); //e.g. FindAncestor(event.srcElement,null,'dragParent');