Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Created October 21, 2013 08:05
Show Gist options
  • Select an option

  • Save jswhisperer/7080224 to your computer and use it in GitHub Desktop.

Select an option

Save jswhisperer/7080224 to your computer and use it in GitHub Desktop.
insertAdjacentHTML javascript
var box2 = document.getElementById("box2");
box2.insertAdjacentHTML('beforebegin', '<div><p>This gets inserted.</p></div>');
//beforebegin
//The HTML would be placed immediately before the element, as a sibling.
//afterbegin
//The HTML would be placed inside the element, before its first child.
//beforeend
//The HTML would be placed inside the element, after its last child.
//afterend
//The HTML would be placed immediately after the element, as a sibling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment