|
Post by Schubaltz on Feb 23, 2008 16:41:05 GMT -5
Just a cross-browser interpretation, only returns true or false, though.
Description: Function that returns true when a specific node lies within the node tree of another.
Syntax: contains(in Node, reference Node)
function contains(a, b) { for(var i = a.childNodes, x = 0; x < i.length; x ++) if(i[x] == b || (i[x].hasChildNodes() && contains(i[x], b))) return true; return false; }
Example:
<html> <head></head> <body> <div><span id="der"></span></div> <script type="text/javascript"> <!-- var i = document.getElementById("der"); if(contains(document.getElementsByTagName("div")[0], i)) i.appendChild(document.createTextNode("Text")); //--> </script> </body> </html>
|
|