1.文档操作
内部插入
???A.append(B) ??????吧B添加到A的后面
???A.appendTo(B) ????吧A添加到B的后面
???A.prepend(B) ?????吧B添加到A的前面
???A.prependTo(B) ???吧A添加到B的前面
外部插入
???A.after(B) ???????吧B添加到A的后面
???A.insertAfter(B) ?吧A添加到B的后面
???A.before(B) ??????吧B添加到A的前面
???A.insertBefore(B) 吧A添加到B的前面
2.克隆操作
$(选择器).clone();
例
<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title>克隆</title></head><body><button class="c1">点我</button><script src="jquery-3.2.1.min.js"></script><script> ???$(".c1").on("click",function () { ???????$(this).clone(true).insertAfter($(this)) ???})</script></body></html>
3.替换操作
replaceWith(content|fn)
?????A.replaceWith(B) ?--> B替换A
replaceAll(selector)
?????A.replaceAll(B) ??--> A替换B
//将所有的h5标题替换为a标签$(‘h5‘).replaceWith(‘<a href="#">hello world</a>‘)//将所有h5标题标签替换成id为app的dom元素$(‘h5‘).replaceWith($(‘#app‘));
4.删除操作
删除节点后,整个标签都会被删除
$(‘ul‘).remove();
删除节点后,事件保留
$(selector).detach();
清空选中元素中的所有后代子节点
//清空掉ul中的子元素,保留ul$(‘ul‘).empty()
38.前端jQuery之文档操作
原文地址:https://www.cnblogs.com/LearningOnline/p/9128707.html