Basic usage of empty() for DOM node deletion

Removing nodes on the page is a common operation for developers. jQuery provides several different methods to deal with this problem. Here we take a closer look at the empty method

empty As the name suggests, the empty method. But it is a little different from deletion, because it only removes all child nodes in the specified element.

This method not only removes child elements (and other descendant elements), but also removes the text within the element. Because, according to the description, any text string in an element is regarded as a child node of the element.

Let’s write an example analysis:

       

p元素1

p元素2

Use a browser to open and run this code, press F12 You can see that the following

< ;/div>not deleted

Continuing Learning
||

p元素1

p元素2

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!