节点操作js jQuery

  • append() - 在被选元素的结尾插入内容
  • prepend() - 在被选元素的开头插入内容
  • after() - 在被选元素之后插入内容
  • before() - 在被选元素之前插入内容

function appendText(){
var txt1="<p class='p'>HTML创建的新元素</p>";
var txt2=$("<p class='p1'></p>").text("jQuery创建的新元素");
var txt3=document.createElement("p");
txt3.innerHTML="dom创建的新元素";
var att = document.createAttribute("class");
att.value = "p2";
txt3.setAttributeNode(att);
$("p").append(txt1,txt2,txt3);
}

 删除remove()

$("p").eq(1).remove();

清空empty()

$("p").eq(0).empty();

原文地址:https://www.cnblogs.com/xingst/p/4949326.html