Posted By

alberomo on 07/25/11


Tagged

manual insertAfter


Versions (?)

insertAfter Function


 / Published in: JavaScript
 

Description: A function to insert a new element after an existed one. Arguments: The new element and the target element the new element should be inserted after.

  1. function insertAfter(newElement,targetElement) {
  2. var parent = targetElement.parentNode;
  3. if (parent.lastChild == targetElement) {
  4. parent.appendChild(newElement);
  5. } else {
  6. parent.insertBefore(newElement,targetElement.nextSibling);
  7. }
  8. }

Report this snippet  

You need to login to post a comment.