Skip to content

Instantly share code, notes, and snippets.

@altair21
Last active August 18, 2016 04:34
Show Gist options
  • Select an option

  • Save altair21/86b331fee79e8d43069e0cbb29019a3b to your computer and use it in GitHub Desktop.

Select an option

Save altair21/86b331fee79e8d43069e0cbb29019a3b to your computer and use it in GitHub Desktop.

Revisions

  1. altair21 revised this gist Aug 18, 2016. No changes.
  2. altair21 created this gist Aug 4, 2016.
    12 changes: 12 additions & 0 deletions addLoadEvent.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    //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();
    }
    }
    }
    9 changes: 9 additions & 0 deletions insertAfter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    //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);
    }
    }