菜鸟不吃菜

节点操作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();

posted on 2015-11-09 10:56  菜鸟不吃菜  阅读(148)  评论(0编辑  收藏  举报

导航