(一)创建节点

如果想把它添加到文档里,可以使用 jQuery中的 append()或者insertAfter()方法或者 before ()等方法。
比如:
var a=$('<p></p>');
var b="<input type='button'/>";
$('#divv').append(a|b);//添加到divv元素的最后.


(二)复制节点
var a = $('<span>节点复制测试</span>');
$('#divv').append(a);
var clone_a = a.clone();
$('#divv').append(clone_a);
克隆后,id一样

(三) 插入节点
在jQuery中插入节点比javascript自带的多了很多,
比如:
.append()
.appendTo()
.prepend()
.prependTo()
.after()
.insertAfter()
.before()
.insertBefore()

(四)删除节点

$('#span1').remove();

(五)替换节点
$("<p>替换 test1 !</p>").replaceAll("#test1");

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-11-28
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2021-12-26
  • 2021-11-30
  • 2021-10-20
相关资源
相似解决方案