<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://www.xianlaiwan.cn/static/lib/jquery/1.9.1/jquery.js"></script>
<style>
.test1 {
background: #bbffaa;
}
.test2 {
background: yellow;
}
</style>
</head>
<body>
<h2>通過insertBefore與insertAfter添加元素</h2>
<button id="bt1">點擊通過jQuery的insertBefore添加元素</button>
<button id="bt2">點擊通過jQuery的insertAfter添加元素</button>
<div class="aaron">
<p class="test1">測試insertBefore,不支持多參數</p>
</div>
<div class="aaron">
<p class="test2">測試insertAfter,不支持多參數</p>
</div>
<script type="text/javascript">
$("#bt1").on('click', function() {
//在test1元素前后插入集合中每個匹配的元素
//不支持多參數
$('<p style="color:red">測試insertBefore方法增加</p>', '<p style="color:red">多參數</p>').insertBefore($(".test1"))
})
</script>
<script type="text/javascript">
$("#bt2").on('click', function() {
//在test2元素前后插入集合中每個匹配的元素
//不支持多參數
$('<p style="color:red">測試insertAfter方法增加</p>', '<p style="color:red">多參數</p>').insertAfter($(".test2"))
})
</script>
</body>
</html>