Ans: To remove the attribute from HTML element use jQuerys removeAttr() methods
The following example will show you how to remove attribute.

<!--
Used basic html and bootstrap skeleton from the below link for style purpose which contains bootstrap.css,bootstrap.js,jquery.js
https://www.w3schools.com/bootstrap/bootstrap_get_started.asp
-->
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>How to remove the attribute(like class, href) from HTML element in jQuery</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">        
    </head>
    <body>
        <div class="container" style="max-width:800px;margin:0 auto;margin-top:50px;">  
            <div>
                <h2 style="margin-bottom:50px;">How to remove the attribute(like class, href) from HTML element in jQuery</h2>              
            </div>
            <div>
                <button type="button" class="remove-href-attr btn btn-success">Remove Link</button>
                <a class="web-link" href="http://www.tutorialsmint.com">tutorialsmint.com</a>
            </div>
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script>
            $(document).ready(function () {
                $(".remove-href-attr").click(function () {
                    $(".web-link").removeAttr("href");
                });
            });
        </script>
    </body>
</html>


This demo removes the href attribute from web-link class before clicking on remove Link hover on tutorialsmint.com. It show it has href attribute. once you click on
 remove attribute it removes the href attribute.
Written by
Check out this Author's contributed articles.
If you like Tutorialsmint and would like to contribute, you can also write an article using Write an Article. See your article appearing on the Tutorialsmint main page and help other programmers to enhance their knowledge.

Comments(0)

RECENT TUTORIALS
Wed Dec 26 • 08:00 AM GMT
Wed Dec 26 • 08:00 AM GMT
Wed Dec 26 • 08:00 AM GMT
Wed Dec 26 • 08:00 AM GMT
Wed Dec 26 • 08:00 AM GMT
Edit Post
Add Reply