Skip to content

Instantly share code, notes, and snippets.

@ghostwriter
Created February 4, 2016 20:05
Show Gist options
  • Save ghostwriter/cf2000de78174b2e1827 to your computer and use it in GitHub Desktop.
Save ghostwriter/cf2000de78174b2e1827 to your computer and use it in GitHub Desktop.
Quick 'n Dirty DOM insertion Function when there is no JS library
// More elaborate code can be found here:
// https://github.com/jquery/jquery/blob/master/src/manipulation.js
function prepend(target, elem) {
target.insertBefore(elem, target.firstChild);
}
function append(target, elem) {
target.appendChild(elem);
}
function before(target, elem) {
target.parentNode.insertBefore(elem, target);
}
function after(target, elem) {
target.parentNode.insertBefore(elem, target.nextSibling);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment