This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9260|Reply: 1

[JavaScript] insertBefore method, and how to implement the insertAfter method

[Copy link]
Posted on 10/19/2018 11:17:51 AM | | |
The js native method insertBefore is used to insert a new element before an element
Definition:

The Node.insertBefore() method inserts a node as a child node of the specified parent node before the reference node.

Syntax: parentElement.insertBefore(newElement, referElement)

It is worth noting
1. If the newElement to be inserted already exists in the DOM tree, then performing this method will remove the node from the DOM tree.
2. If the referElement is null, then the newElement is added to the end of the child node of the parent node

Since there is no insertAfter method native in JS, how to implement this function?

The element node also has a property: nextSibling, which points to the element's next sibling element, which is null if it is already a final child node.

Based on the above, the insertAfter function can be implemented







Previous:Fixed menu/top-level plugin Sticky-Kit bug solution in angular
Next:Route jump to Navigate in angular2 router
Posted on 10/22/2018 2:02:53 PM |
Not bad
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com