zoukankan      html  css  js  c++  java
  • 原生js删除、添加、查找、替换元素

    1、创建元素节点:createElement
    document.createElement("p");//创建p标签;
    document.createTextNode("txt");//创建文本标签;

    2、插入节点:appendchild:在要插入的元素节点上调用,他插入指定的节点使其成为那个节点的最后一个子节点。
    insertBefore:在已有的元素前插入一个新元素;
    insertAfter:在现有的元素后面插入一个新元素;

    3、删除节点:removeChild;从文档树中删除一个节点(先找到要删除节点的父节点,用父节点删除);
    var para1=document.getElementById("p1");
    para1.parentNode.removeChild(para1);

    4、替换节点:replaceChild;将一个节点替换为另一个节点(先找到要替换的节点的父节点,用父节点替换);
    ele.replaceChild(oSpan,oBox);

    5、添加节点:appendChild;从文档树中添加一个节点;
    eleParent.appendChild(childEle);

    6、查找节点:
    document.body.querySelector("#id||.class||tag")
    document.body.querySelectorAll("#id||.class||tag")


    链接:https://www.jianshu.com/p/e707f52f44d2
    来源:简书
  • 相关阅读:
    数据库操作
    jquery 第一章
    算法很美 第一章
    python 学习第四天
    python学习第三天
    python学习第二天
    学习python的第一天
    C#-线程
    C#-流、存储
    C#-集合
  • 原文地址:https://www.cnblogs.com/lydiawork/p/13476899.html
Copyright © 2011-2022 走看看