Home > Web Front-end > Front-end Q&A > How to disable hyperlinks in jquery

How to disable hyperlinks in jquery

WBOY
Release: 2022-04-02 11:47:43
Original
2583 people have browsed it

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');".

How to disable hyperlinks in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to disable hyperlinks in jquery

The removeAttr() method removes one or more attributes from the selected element.

Syntax

$(selector).removeAttr(attribute)
Copy after login

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(&#39;href&#39;);
});
});
</script>
</head>
<body>
<a href="//m.sbmmt.com">这是一个链接</a>
<button>禁用这个链接</button>
</body>
</html>
Copy after login

Output result:

How to disable hyperlinks in jquery

##Related video tutorial Recommended:

jQuery video tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template