Home > Web Front-end > JS Tutorial > JavaScript expands DOM operations prependChild insertAfert_DOM

JavaScript expands DOM operations prependChild insertAfert_DOM

WBOY
Release: 2016-05-16 18:16:19
Original
1606 people have browsed it

The following is an extended function I wrote. Although it is already available online, it is only used for my own training. . .

Copy code The code is as follows:

function prependChild(o,s){
if (s.hasChildNodes()){
s.insertBefore(o,s.firstChild);
}else{
s.appendChild(o);
}
}
function insertAfert(o,s){
if(s.nextSibling!=null){
s.parentNode.insertBefore(o,s.nextSibling);
}else{
s.parentNode.appendChild (o);
}
}
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