Home > Web Front-end > JS Tutorial > body text

How to delete elements by clicking in jquery

WBOY
Release: 2021-11-22 14:29:12
Original
3983 people have browsed it

Method: 1. Use the click() method to bind a click event to the button element and specify an event processing function; 2. Use the remove() method in the processing function to delete the element, and the syntax is "$(" button Element").click(function(){$("Element to be removed").remove();})".

How to delete elements by clicking in jquery

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

How jquery implements click-to-delete elements

The first step is to delete elements. You can delete the selected elements through jquery's remove() and remove(). elements and sub-elements.

The second step is to introduce how to delete elements with jQuery through examples. Create a new html page, introduce jquery.js, add a div box to the page body, add two paragraphs to the div box, and delete a div element. button, call the $("#div1").remove() method in js to delete the element, as shown in the following figure:

How to delete elements by clicking in jquery

The third step is to open the html in the browser After the page, you can see the div box and two paragraphs. Click the remove div element button, as shown below:

How to delete elements by clicking in jquery

After clicking the button:

How to delete elements by clicking in jquery

Recommended related video tutorials: jQuery video tutorial

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

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