Last active
August 18, 2016 04:34
-
-
Save altair21/86b331fee79e8d43069e0cbb29019a3b to your computer and use it in GitHub Desktop.
《DOM Scripting》 suggest function
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
//add function to run after windown.onload | |
function addLoadEvent(func) { | |
var oldonload = window.onload; | |
if (typeof window.onload != 'function') { | |
window.onload = func; | |
} else { | |
window.onload = function() { | |
oldonload(); | |
func(); | |
} | |
} | |
} |
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
//JavaScript DOM only have insert one element before another function called "insertBefore", this for insert one after another | |
function insertAfter(newElement, targetElement) { | |
var parent = targetElement.parentNode; | |
if (parent.lastChild === targetElement) { | |
parent.appendChild(newElement); | |
} else { | |
parent.insertBefore(newElement, targetElement.nextSibling); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment