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

JavaScript expands DOM operations prependChild insertAfert_DOM

WBOY
WBOYOriginal
2016-05-16 18:16:191588browse

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);
}
}
Statement:
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