• insertAfter()


    <div id="b">bbbbbbbbb</div>
    <div>dddddd</div>

    JavaScript

    window.onload=function(){
           var a =document.createElement("span");
           var b =document.createTextNode("cssrain");
           a.appendChild(b);
           
           var mubiao = document.getElementById("b");
           insertAfter(a,mubiao); 
        }
    
        function insertAfter(newElement,targetElement) {
            var parent = targetElement.parentNode;
                if (parent.lastChild == targetElement) {// 如果最后的节点是目标元素,则直接添加。因为默认是最后
                    parent.appendChild(newElement);
                } else {
                    parent.insertBefore(newElement,targetElement.nextSibling);//如果不是,则插入在目标元素的下一个兄弟节点的前面。也就是目标元素的后面。
                }
        }
  • 相关阅读:
    Mysql基础
    Mysql基础2
    Windows CMD命令大全
    python 调试方法
    LDAP
    Linux 内核与模块调试
    Linux tee命令
    Linux kgdb命令
    OpenSSL基础知识
    Linux top命令
  • 原文地址:https://www.cnblogs.com/leejersey/p/3185518.html
Copyright © 2020-2023  润新知