Home > Web Front-end > JS Tutorial > Javascript insertAfter() implements function code_javascript skills

Javascript insertAfter() implements function code_javascript skills

WBOY
Release: 2016-05-16 18:00:53
Original
1312 people have browsed it
Copy code The code is as follows:

//DOM does not provide insertAfter() method
function insertAfter( newElement, targetElement){
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
// If the last node is the target element, add it directly. Because the default is the last
parent.appendChild(newElement);
}
else {
parent.insertBefore(newElement, targetElement.nextSibling);
//If not, insert in the target element in front of the next sibling node. That is, behind the target element
}
}


jQuery document operation - insertAfter() method
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template