<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>删除节点</title>
<script src="../jQuery-2.1.0/jquery-2.1.0.js"></script>
<script>
$(function(){
$("p").click(function(){
alert($(this).html());
});
//1.点击事件
$("button:eq(0)").click(function(){
//2.删除标签
var myP = $("p").remove();
//alert(myP.html());
$("h3").after(myP);
});
//1.点击事件
$("button:eq(1)").click(function(){
//2.删除标签
var myP = $("p").detach();
//alert(myP.html());
$("h3").after(myP);
});
//1.点击事件
$("button:eq(2)").click(function(){
//2.删除标签
var myP = $("p").empty();
myP.html("这是清空之后的p标签");
//alert(myP.html());
$("h3").after(myP);
});
$("li:eq(0)").click(function(){
alert($(this).html());
});
//1.点击事件
$("button:eq(3)").click(function(){
//2.复制节点
var li = $("li:eq(0)").clone(true);
$("ul").append(li);
});
//1.点击事件
$("button:eq(4)").click(function(){
//2.复制节点
$("li:eq(2)").replaceWith("<li>替换节点</li>");
});
});
</script>
</head>
<body>
<button>remove删除</button>
<button>detach删除</button>
<button>empty清空</button>
<button>复制节点</button>
<button>替换节点</button>
<p class="haha">p标签</p>
<h3>测试删除方法</h3>
<ul>
<li>北京</li>
<li>上海</li>
<li>广州</li>
<li>深圳</li>
</ul>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>删除节点</title>
<script src="../jQuery-2.1.0/jquery-2.1.0.js"></script>
<script>
$(function(){
$("p").click(function(){
alert($(this).html());
});
//1.点击事件
$("button:eq(0)").click(function(){
//2.删除标签
var myP = $("p").remove();
//alert(myP.html());
$("h3").after(myP);
});
//1.点击事件
$("button:eq(1)").click(function(){
//2.删除标签
var myP = $("p").detach();
//alert(myP.html());
$("h3").after(myP);
});
//1.点击事件
$("button:eq(2)").click(function(){
//2.删除标签
var myP = $("p").empty();
myP.html("这是清空之后的p标签");
//alert(myP.html());
$("h3").after(myP);
});
$("li:eq(0)").click(function(){
alert($(this).html());
});
//1.点击事件
$("button:eq(3)").click(function(){
//2.复制节点
var li = $("li:eq(0)").clone(true);
$("ul").append(li);
});
//1.点击事件
$("button:eq(4)").click(function(){
//2.复制节点
$("li:eq(2)").replaceWith("<li>替换节点</li>");
});
});
</script>
</head>
<body>
<button>remove删除</button>
<button>detach删除</button>
<button>empty清空</button>
<button>复制节点</button>
<button>替换节点</button>
<p class="haha">p标签</p>
<h3>测试删除方法</h3>
<ul>
<li>北京</li>
<li>上海</li>
<li>广州</li>
<li>深圳</li>
</ul>
</body>
</html>