Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting an element

Tags:

javascript

Is there a method in Javascript to insert an element after the current node.I know there is a method which inserts an element before the current node of the XML.But is there a method to Ins. after the current node?

like image 798
Harish Avatar asked Dec 17 '25 14:12

Harish


1 Answers

Just get the next sibling of the current node and insert the new node before that node using insertBefore:

currentNode.parentNode.insertBefore(newNode, currentNode.nextSibling);

If nextSibling is null, insertBefore inserts the new node at the end of the node list.

like image 142
Gumbo Avatar answered Dec 19 '25 05:12

Gumbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!