Created
February 13, 2013 03:16
-
-
Save rainyjune/4941980 to your computer and use it in GitHub Desktop.
DOM manipulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function firstElementChild(e) { | |
var e = e || document.documentElement; | |
return e.firstElementChild || e.children[0] || null; | |
} | |
function lastElementChild(e) { | |
var e = e || document.documentElement; | |
return e.lastElementChild || e.children[e.children.length-1] || null; | |
} | |
function nextElementSibling(e) { | |
if(e.nextElementSibling) return e.nextElementSibling; | |
for(e = e.nextSibling; e && e.nodeType !== 1; e = e.nextSibling); | |
return e; | |
} | |
function previousElementSibling(e) { | |
if(e.previousElementSibling) return e.previousElementSibling; | |
for(e = e.previousSibling; e && e.nodeType !== 1; e = e.previousSibling); | |
return e; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment