The DOM node deletes the empty and remove
Just learned new knowledge, although it is a small knowledge point, but still can't help but want to share with you.
. Empty () is the deletion of descendants of that node, with the result that the node is emptied (there are no elements inside that node).
. Remove () is the deletion of the node, which results in the deletion of the node (the node and its descendant elements will not exist).
Put the code below to illustrate.
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script src= "Http://libs.baidu.com/jquery/1.9.1/jquery.js" ></script>
<style>
body{
Background: #ffe5aa;
}
#test1 {
width:100px;
height:100px;
Background: #3db7ff;
}
#test2 {
width:100px;
height:100px;
Background: #ff179f;
}
</style>
<body>
<div class= "whole" >
<button class= "bt1" > Delete nodes via empty </button>
<button class= "BT2" > Remove nodes via Remove </button>
</div>
<div id= "Test1" >
<p> Elemental 1</p>
<p> Elemental 2</p>
</div>
<div id= "Test2" >
<p> Elemental 3</p>
<p> Elemental 4</p>
</div>
<script type= "Text/javascript" >
$ (". Bt1"). On (' click ', function () {
$ ("#test1"). empty ();
})
$ (". Bt2"). On (' click ', function () {
$ ("#test2"). Remove ();
})
</script>
</body>
When you click Run, the following screen appears.
Click Button1, the. Empty () directive is executed, and the Test1 child node element is expected to be deleted. The results are as follows.
Click Button2 again to execute the. Remove () directive. It is expected that the test2 and its descendants child node elements will be deleted. The results are as follows.
The above is the DOM node deletion of the difference between empty and remove, the first time to write a blog, not good please understand.
The DOM node deletes the empty and remove