//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com //*** 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.) // Find an ancestor element of 'el' with the correct tagName // and/or where a certain attribute equals the supplied value function Ancestor(el,tagName,attr,value){ if (tagName) tagName=tagName.toLowerCase(); while (el){ if((!tagName || (el.tagName && tagName==el.tagName.toLowerCase())) && (!attr || (typeof(el.getAttribute)=='function' && el.getAttribute(attr)==value))) return el; el=el.parentNode; } return null; } // examples: // var myParentTable = Ancestor(this,'table'); // var selectedParent = Ancestor(this,null,'className','selected'); // var insideAValidatingForm = Ancestor(this,'form','autoValidate','true'); // Version 1.5 ... now with even less incorrect slop!