Home  >  Article  >  Daily Programming  >  How to delete element node with jQuery

How to delete element node with jQuery

藏色散人
藏色散人Original
2018-12-07 14:46:187822browse



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>

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:
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