How to Remove Attributes from HTML Element in jQuery
In this tutorial, we are going to see how to remove attributes from HTML element in jQuery. In the example bellow, when you click the “Remove link” button, the “href” attribute will be removed from the link using the removeAttr() method of jQuery.
How to Remove Attributes from HTML Element in jQuery
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Remove Attributes from HTML Element</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".sup-attr").click(function(){ $("a").removeAttr("href"); }); }); </script> </head> <body> <button type="button" class="sup-attr">Remove link</button> <a href="https://stackhowto.com">www.stackhowto.com</a> </body> </html>
Result |
---|
www.stackhowto.com |