Skip to content

Instantly share code, notes, and snippets.

@vlakoff
Created September 2, 2015 08:29
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 vlakoff/f770899d03953a7fc07e to your computer and use it in GitHub Desktop.
Save vlakoff/f770899d03953a7fc07e to your computer and use it in GitHub Desktop.
Functions for quick'n'dirty DOM insertion when there is no JS library
// for more elaborate code, see for instance:
// 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