Suppose the following HTML code
<DivID= "Mydiv"style= "width:100px;height:100px;border:1px solid red">XXX<Div>S1</Div> <Div>S2</Div></Div>
The following methods can be used to delete a node operation:
$ ("#mydiv"). Remove (); The Remove method removes the Mydiv node itself, as well as all the content beneath it, and the child nodes
$ ("#mydiv"). empty (); Empty does not delete the Mydiv node itself, only the content under the node (including child nodes)
$ ("#mydiv"). Children (). remove (); Delete all the child nodes under Mydiv. The main text below will not be deleted, such as the XXX information above will not be deleted
$ ("#mydiv div"). Remove (); Effect with $ ("#mydiv"). Children (). remove ();
In summary, in most scenarios, to delete all child nodes, use the empty method; To delete itself and child nodes, use the Remove method.
jquery Learning notes: Removing nodes from operations