Q:

How to remove the attribute from an HTML element in jQuery

0

How to remove the attribute from an HTML element in jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery removeAttr() methods

You can use the jQuery removeAttr() method to remove the attributes from an HTML element.

In the following example when you click the "Remove Link" button it will remove the href attribute from the link. Let's try it out and see how this method works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Removing Attribute from HTML Element</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function() {
        $(".remove-attr").click(function(){            
            $("a").removeAttr("href");
        });
    });
</script> 
</head>
<body>
    <button type="button" class="remove-attr">Remove Link</button>
    <a href="#">Demo Link</a>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to add new elements to DOM in jQuery... >>
<< How to add attributes to an HTML element in jQuery...