/ 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.
Arguments: The new element and the target element the
new element should be inserted after.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function insertAfter(newElement,targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement,targetElement.nextSibling); } }