Home Daily Programming HTML Knowledge How to delete element node with jQuery

How to delete element node with jQuery

Dec 07, 2018 pm 02:46 PM



The jquery method of deleting element nodes is very simple. We can delete the node directly through the remove() method.

How to delete element node with jQuery

Now we will give you a detailed introduction to the jquery method of deleting node elements with a simple code example.

The code example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jquery删除节点示例</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
 $(function () {
            $("button").click(function () {
                $("p").remove();
 });

 })

    </script>
</head>
<body>
<button>删除</button>
<h1>这是标题</h1>
<p>这是一段话。</p>
</body>
</html>
Copy after login

Here we wrote a click event click. When the delete button is clicked, an event will be triggered to delete the p tag through the remove method.

The final effect is as shown below:

How to delete element node with jQuery

.remove([selector]):A selector expression , used to filter the set of matching elements to be deleted.

Note: The .remove() method obtains elements from the DOM. When using .remove(), you need to delete the element itself. In addition to the element itself, all bound events and jQuery data associated with the element are removed. To delete elements without deleting data and events, use .detach().

This article is a detailed introduction to jQuery deleting element nodes. It is also very simple and easy to understand. I hope it will be helpful to friends in need!



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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)