/ Published in: JavaScript
A few functions to handle DOM events (firstChild, nextSibling, firstSibling, lastSibling)
Accounts for firefox treating /n as a node.
Expand |
Embed | Plain Text
//dom javascript functions function firstChild(startParent){ var tempObj = startParent.firstChild; while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){ tempObj = tempObj.nextSibling; } return (tempObj.nodeType==1)?tempObj:false; } function nextSibling(startBrother){ var tempObj = startBrother.nextSibling; while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){ tempObj = tempObj.nextSibling; } return (tempObj.nodeType==1)?tempObj:false; } function firstSibling(node){ var tempObj=node.parentNode.firstChild; while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){ tempObj=tempObj.nextSibling; } return (tempObj.nodeType==1)?tempObj:false; } function lastSibling(node){ var tempObj=node.parentNode.lastChild; while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){ tempObj=tempObj.previousSibling; } return (tempObj.nodeType==1)?tempObj:false; }
You need to login to post a comment.
