Home>Article>Web Front-end> How to delete html elements with jquery

How to delete html elements with jquery

青灯夜游
青灯夜游 Original
2021-05-19 16:49:20 4193browse

Delete method: 1. Use the remove() method to delete the selected element and its sub-elements, the syntax "$(selector).remove()"; 2. Use the empty() method to delete the selected element and its sub-elements from the selected element. To delete child elements from a selected element, the syntax is "$(selector).empty()".

How to delete html elements with jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

If you need to delete elements and content, you can generally use the following two jQuery methods:

  • remove() - delete the selected element (and its sub-elements)

  • empty() - Removes child elements from the selected element

jQuery remove() method

jQuery remove() method removes the selected element and its child elements.

      
这是 div 中的一些文本。

这是在 div 中的一个段落。

这是在 div 中的另外一个段落。


Rendering:

How to delete html elements with jquery

jQuery empty() method

jQuery empty() method deletes the selected The child elements of the element.

      
这是 div 中的一些文本。

这是在 div 中的一个段落。

这是在 div 中的另外一个段落。


Rendering:

How to delete html elements with jquery

Recommended related video tutorials:jQuery Tutorial(Video)

The above is the detailed content of How to delete html elements with jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn