![]()
Snippets of A |
|
|
What are snippets? |
|
onclick upon an image has been performed upon an image nested within, say, a DIV tag with some specific id or className or whatever.
function getParent(element, parent){ if(typeof element=="string"){element=document.getElementById(element);}; if(!element){return null;}; var elements=[]; if(typeof parent!="string"){/*no parent: gets all parents till #document*/ while(element.parentNode){ element=element.parentNode; elements.unshift(element); if(element==parent){return elements;}; } } else{/*string, presumes you want to locate the first parent node that is such TAG*/ parent=parent.toUpperCase(); while(element.parentNode){ element=element.parentNode; elements.unshift(element); if(element.nodeName && element.nodeName.toUpperCase()==parent){return elements;}; } }; return elements; /* keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
document.getElementById or as the string id of the node.
document.getElementById, or a string: in this last case it is presumed the string is the first tag name (instance: "DIV") that you want to locate as parent of the first passed node.
null if the input was not a valid DOM node, or an array holding all the parent node objects traversed in the process, with the outermost nodes starting at index 0. Therefore if you were looking for one specific node, it will be always located at entry 0 if found.
<div id="outerdiv"> <div id="innermostdiv" class="divin"> <ul> <li id='foo'>blah blah</li> </ul> </div> </div> <script> var foundnodes=getParent('foo', 'DIV'); alert(foundnodes[0].nodeName+' '+foundnodes[0].id+' '+foundnodes[0].className); </script>Remove colors