WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to remove the attribute from an HTML element in jQuery

Topic: JavaScript / jQueryPrev|Next

Answer: Use the jQuery removeAttr() methods

The following example will show you how to remove attributes from an HTML element using jQuery.

In the example when you click the Remove Link button it will remove the href attribute from the link using the jQuery removeAttr() method.

  • <!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-1.12.4.min.js"></script>
  • <script type="text/javascript">
  •     $(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>

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.