Node append
##Father-child relationship append
append(content): Append content to each matching element
prepend(content): Append content to the inside of each matching element
appendTo(content): Append all matching elements after Append to another, specified element collection
prependTo(content): Prepend all matching elements to another, specified set The examples of
<!DOCTYPE html>
<html>
<head>
<title>php.cn</title>
<meta charset="utf-8" />
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
function f1(){
//主动追加
//新节点追加
//append() 后置
$("#yi").append("<li>成都市</li>");
//prepend() 前置
$("#yi").prepend("<li>杭州市</li>");
//已有节点追加(节点发生物理位置移动)
$("#yi").append($("#gai"));
}
function f2(){
//被动追加
//appendTo 后置追加
//prependTo 前置追加
//新节点追加
$("<li>武汉市</li>").appendTo('#yi');
$("<li>天津市</li>").prependTo('#yi');
//$("html标签")---创建节点--->createElement等方法
//已有节点追加
$('#er li:eq(1)').appendTo('#yi');
}
</script>
<style type="text/css">
div {width:300px; height:200px; background-color:pink;}
</style>
</head>
<body>
<ul id="yi">
<li>北京</li>
<li>上海</li>
<li>广州</li>
</ul>
<ul id="er">
<li>福州市</li>
<li>合肥市</li>
<li id="gai">郑州市</li>
</ul>
<input type="button" value="追加1" onclick="f1()" />
<input type="button" value="追加2" onclick="f2()" />
</body>
</html> Brother relationship append
<!DOCTYPE html>
<html>
<head>
<title>php.cn</title>
<meta charset="utf-8" />
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
function f1(){
//主动追加
//after() 后置追加
//before() 前置追加
//新节点
$('#yi li:last').after("<li>深圳</li>");
$('#yi li:first').after("<li>成都市</li>");
$('#fei').before("<li>杭州市</li>");
//已有节点追加
$('#fei').after($('#gai'));
}
</script>
<style type="text/css">
div {width:300px; height:200px; background-color:pink;}
</style>
</head>
<body>
<ul id="yi">
<li>北京</li>
<li id="fei">上海</li>
<li>广州</li>
</ul>
<ul id="er">
<li>福州市</li>
<li>合肥市</li>
<li id="gai">郑州市</li>
</ul>
<input type="button" value="追加1" onclick="f1()" />
</body>
</html>