Home > Web Front-end > JS Tutorial > Example of usage of detach() method in jQuery_jquery

Example of usage of detach() method in jQuery_jquery

WBOY
Release: 2016-05-16 16:24:36
Original
1188 people have browsed it

The example in this article describes the usage of the detach() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method removes all matching elements from the DOM.

Note: The detach() method will not delete the matching elements from the jQuery object, so these matching elements can be used again in the future. Unlike remove(), all bound Events, attached data, etc. are retained.

Grammar structure:

Copy code The code is as follows:
$(selector).detach(expr)

Parameter list:

参数 描述
expr 可选。用于筛选被删除元素的jQuery表达式。
Example code:

Example 1:

Copy code The code is as follows:






Script Home




Welcome to the script home

Script House welcomes you




The above code can delete the div with the id value first in the div collection.

Example 2:

Copy code The code is as follows:






Script Home




Welcome to the script home

Script Home welcomes you




If the method has no parameters, all matching elements will be deleted.

Example 3:

Copy code The code is as follows:






Script Home




Welcome to the script home

Script House welcomes you





As can be seen from the running results of the above code, this method does not delete the div from the jquery object.

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template