Home >Web Front-end >JS Tutorial >Basic introduction to remove in jQuery and comparison of differences between empty

Basic introduction to remove in jQuery and comparison of differences between empty

巴扎黑
巴扎黑Original
2017-06-25 09:37:041440browse

Definition and Usage

remove() method removes the selected element, including all text and child nodes.

This method does not remove the matching elements from the jQuery object, so these matching elements can be used again in the future.

But in addition to the element itself being retained, remove() will not retain the jQuery data of the element. Others such as bound events, additional data, etc. will be removed. This is different from detach().

Syntax

$(selector).remove()

The difference between JQuery empty method and remove method

1. JQuery empty method
A. Definition and Usage
The empty() method removes all content from the selected element, including all text and child nodes.
B. Syntax
$(selector).empty();
2. JQuery remove method

A. Definition and usage
The remove() method removes the selected element. Includes all text and child nodes.

This method does not remove the matching elements from the jQuery object, so these matching elements can be used again in the future.

But in addition to the element itself being retained, remove() will not retain the jQuery data of the element. Others such as bound events, additional data, etc. will be removed. This is different from detach().
B. Grammar
The text in ;dsfsd

is removed, leaving

, which still retains its position in the dom.

$("p").remove() deletes it from the dom without retaining its position.

The above is the detailed content of Basic introduction to remove in jQuery and comparison of differences between empty. 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