3.3 文档处理
内部插入
$("#c1").append("<b>hello</b>");//把hello插入#c1到最后一项
$("p").appendTo("div"); //包p插入到div中
prepend();//插入到最上面项
prependTo()
外部插入
before()
insertBefore()
after()
insertAfter()
replaceWith()
remove()
empty()
clone()
实例 clone方法的应用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="outer">
<div class="condition">
<div class="icons" style="display:inline-block">
<a onclick="add(this);"><button>+</button></a>
</div>
<div class="input" style="display:inline-block">
<input type="checkbox">
<input type="text" value="alex">
</div>
</div>
</div>
<script src="js/jquery-2.2.3.js"></script>
<script>
function add(self){
var $duplicate = $(self).parent().parent().clone();
$duplicate.find('a[onclick="add(this);"]').attr('onclick',"removed(this)").children("").text("-");
$duplicate.appendTo($(self).parent().parent().parent());
}
function removed(self){
$(self).parent().parent().remove()
}
</script>
</body>
</html>