The following post will explain how the pointer event property is used in a code to disable a link in an HTML document.
Disabling a Link Using CSS
CSS library is used in combination with other languages like HTML. So, if an HTML document has a link to directly visit any other web page, the CSS pointer-events property is used to disable a link:
cursor: default;
How to Use pointer-events Property in Code?
The CSS style statement in which we will add the pointer-events property to disable the link should refer to the class that contains the link. For example, if we have a class named “not-active” that contains the link:
In the above code, the clickable link has a class “not-active” which will be used to access this HTML element.
The above code does generate the following output:
Clicking the link directs the user to the google search engine:
The pointer-event Property
- Inside a CSS style element, write the pointer event property (pointer-event: none) while referring to the class (not-active) containing the link that should be disabled.
- Set the cursor as any of the options like default, none, pointer, etc.
.not-active {
pointer-events: none;
cursor: default;
}
</style>
After executing the code, there will be no change in the graphical display of the link from the outside, but when the user clicks it, it will not do anything:
This was the easiest way to disable the link in a code using CSS statements.
Conclusion
A link that directs the user to other web pages can easily be disabled through a simple CSS “pointer-events: none” property. This does not require any changes to the logic of the code or the class in which the link has been created. A simple pointer event property in the style element referring to the class containing the link is required.