Introduction of append of and appendTo of for node insertion
- 2020-03-30 01:22:57
- OfStack
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function(){
//The use of the append ()
//$("ul").append("<li title='abc'>hello</li>");
//$("ul").append("<li title='xyz'>world</li>");
//The use of the appendTo ()
$("<li title='xyz'>hello</li>").appendTo($("ul"));
});
</script>
</head>
<body>
<p title="hello world"> What do you think of the training in shengsi park? </p>
<ul>
<li title="1"> good </li>
<li title="2"> Very good </li>
<li title="3"> Very good </li>
<li title="4"> Very good </li>
<li title="5"> Too good </li>
<li title="6"> Good beyond description </li>
</ul>
</body>
</html>
Operates on an existing node
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery4</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function(){
var li1 = $("<li title='abc'>hello</li>");
var li2 = $("<li title='abc'>world</li>");
var li3 = $("<li title='abc'>hello world</li>");
$("ul").append(li1);
$("ul").prepend(li2);
$("ul li:eq(4)").after(li3);
});
</script>
</head>
<body>
<p title="hello world"> What do you think of the training in shengsi park? </p>
<ul>
<li title="1"> good </li>
<li title="2"> Very good </li>
<li title="3"> Very good </li>
<li title="4"> Very good </li>
<li title="5"> Too good </li>
<li title="6"> Good beyond description </li>
</ul>
</body>
</html>