Home > Daily Programming > HTML Knowledge > How to delete html attributes in jquery

How to delete html attributes in jquery

藏色散人
Release: 2018-12-19 09:51:56
Original
6294 people have browsed it

Sometimes we may need to remove a wrapper or parent element, such as removing anchor tags around text. So if we want to use jquery to delete html attributes, we can use the jQuery unwrap() method. This method can easily delete the wrapping element and keep the internal HTML or text content unchanged.

How to delete html attributes in jquery

Now we will introduce to you the jquery method of deleting html attributes based on specific code examples.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jquery删除html属性示例</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
 $(function(){
            $("button").click(function(){
                $("p").find("a.link").contents().unwrap();
 });
 });
 </script>
</head>
<body>
<P>如果你单击以下按钮,它将从其中删除锚标记<a href="#" class="link">此链接</a>但是要保持文本的完整性 </P>
<button type="button">删除链接</button>

</body>
</html>
Copy after login

The effect is as shown below:

How to delete html attributes in jquery

##unwrap() method means to delete the parent element of the matching element set from the DOM. and leaves matching elements in place. The .unwrap() method removes the element's parent element and returns the unwrapped content. This is actually the inverse of the .wrap() method. Matching elements replace their parent nodes in the DOM structure.

find() Method to get the descendants of each element in the current element collection, filtered by selector, jQuery object or element.

contents() Method to obtain the child nodes of each element in the matching element collection, including text and comment nodes.

This article is about the method of deleting html attributes in jquery. It is very simple. I hope it will be helpful to friends in need!

The above is the detailed content of How to delete html attributes 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