Skip to content

Instantly share code, notes, and snippets.

@altair21
Last active August 18, 2016 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altair21/86b331fee79e8d43069e0cbb29019a3b to your computer and use it in GitHub Desktop.
Save altair21/86b331fee79e8d43069e0cbb29019a3b to your computer and use it in GitHub Desktop.
《DOM Scripting》 suggest function
//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();
}
}
}
//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