Skip to content

Instantly share code, notes, and snippets.

@altair21 altair21/addLoadEvent.js
Last active Aug 18, 2016

Embed
What would you like to do?
《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
You can’t perform that action at this time.