In jquery, you can use the removeAttr() method to disable the hyperlink. This method can delete the attributes in the element. Just delete the "href" attribute of the hyperlink element. The syntax is "hyperlink element object" ..removeAttr('href');".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
The removeAttr() method removes one or more attributes from the selected element.
Syntax
$(selector).removeAttr(attribute)
attribute required. Specifies one or more properties to remove. To remove several properties, separate the property names with spaces.
Remove the href attribute in the a tag
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("a").removeAttr('href'); }); }); </script> </head> <body> <a href="//m.sbmmt.com">这是一个链接</a> <button>禁用这个链接</button> </body> </html>
Output result:
##Related video tutorial Recommended:The above is the detailed content of How to disable hyperlinks in jquery. For more information, please follow other related articles on the PHP Chinese website!