Use pure CSS to disable the a tag in HTML without JavaScript

Use pure CSS to disable the a tag in HTML without JavaScript
In fact, this problem has already popped up when I first learned the select tag in HTML. To this day, I still haven't found a way to disable the a tag using pure CSS. I have asked my colleagues, classmates, and teachers, and they all used JavaScript. Is it really necessary to use JavaScript?

1. Use pure CSS to disable the a tag in HTML:

Copy code
The code is as follows:

<html>
<head>
<title>How to disable the a tag</title>
<metacontent="text/html; charset=GB2312"http-equiv="Content-Type">
<style type="text/css">
body{
font:12px/1.5 \5B8B\4F53, Georgia, Times New Roman, serif, arial;
}
a{
text-decoration:none;
outline:0 none;
}
.disableCss{
pointer-events:none;
color:#afafaf;
cursor:default
}
</style>
</head>
<body>
<aclass="disableCss" href="http://www.baidu.com/">Baidu</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<aclass="disableCss" href="#"onclick="javascript:alert('Hello!!!');">Click</a>
</body>
</html>

Although pure CSS is used above to disable the a tag, since Opera and IE browsers do not support the pointer-events style, the above code cannot disable the a tag in these two browsers.

2. Use Jquery and CSS to disable the a tag in HTML:

Copy code
The code is as follows:

<html>
<head>
<title>02 ——Disabling the a tag in HTML with Jquery and CSS</title>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
<script type="text/javascript" src="./jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function() {
$('.disableCss').removeAttr('href'); //Remove the href attribute in the a tag
$('.disableCss').removeAttr('onclick'); //Remove the onclick event in the a tag
});
</script>
<style type="text/css">
body {
font: 12px/1.5 \5B8B\4F53, Georgia, Times New Roman, serif, arial;
}
a {
text-decoration: none;
outline: 0 none;
}
.disableCss {
color: #afafaf;
cursor: default
}
</style>
</head>
<body>
<a class="disableCss" href="http://www.baidu.com/">Baidu</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="disableCss" href="#" onclick="javascript:alert('Hello!!!');">Click</a>
</body>
</html>

This method is compatible with all browsers, but it mixes JavaScript, which is probably a fatal flaw! ! !

3. Use Jquery to disable the a tag in HTML:

Copy code
The code is as follows:

<html>
<head>
<title>03 ——Disabling the a tag in HTML with Jquery</title>
<meta content="text/html; charset=GB2312" http-equiv="Content-Type">
<script type="text/javascript" src="./jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function() {
$('.disableCss').removeAttr('href'); //Remove the href attribute in the a tag
$('.disableCss').removeAttr('onclick'); //Remove the onclick event in the a tag
$(".disableCss").css("font","12px/1.5 \\5B8B\\4F53, Georgia, Times New Roman, serif, arial");
$(".disableCss").css("text-decoration","none");
$(".disableCss").css("color","#afafaf");
$(".disableCss").css("outline","0 none");
$(".disableCss").css("cursor","default");
});
</script>
</head>
<body>
<a class="disableCss" href="http://www.baidu.com/">Baidu</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="disableCss" href="#" onclick="javascript:alert('Hello!!!');">Click</a>
</body>
</html>

Pure Jquery is used above to implement the function of disabling the a tag in HTML.

<<:  A brief analysis of CSS :is() and :where() coming to browsers soon

>>:  How to set an alias for a custom path in Vue

Recommend

Nginx location matching rule example

1. Grammar location [=|~|~*|^~|@] /uri/ { ... } 2...

CSS and HTML and front-end technology layer diagram

The relationship between Javascript and DOM is ve...

CSS3 realizes the website product display effect diagram

This article introduces the effect of website pro...

Reasons and solutions for the failure of React event throttling effect

Table of contents The problem here is: Solution 1...

Windows 2019 Activation Tutorial (Office2019)

A few days ago, I found that the official version...

Discuss the development trend of Baidu Encyclopedia UI

<br />The official version of Baidu Encyclop...

MySQL 5.7 and above version download and installation graphic tutorial

1. Download 1. MySQL official website download ad...

MySQL 5.7 zip archive version installation tutorial

This article shares the installation tutorial of ...

About MYSQL, you need to know the data types and operation tables

Data Types and Operations Data Table 1.1 MySQL ty...

A comprehensive understanding of Vue.js functional components

Table of contents Preface React Functional Compon...

Detailed explanation of the usage of two types of temporary tables in MySQL

External temporary tables A temporary table creat...

Html+css to achieve pure text and buttons with icons

This article summarizes the implementation method...

How to forget the password of Jenkins in Linux

1.Jenkins installation steps: https://www.jb51.ne...