0

Best Way to enable, disable links in jquery

This is a Fast & Easy Tutorial about enabling & Disabling links  in JQuery.Some time in our website/blog we have to enable disable links on any activity or jQuery event. For Example you need to process some information in website background and need to disable links then below code example is for you.

disable a href javascript, disable hyperlink html, jquery disable href anchor, jquery disable href onclick, jquery disable link after click, jquery disable link click event, jquery hide link, jquery make link unclickable

Here i have created a simple html page with some anchor tags (links).

These are the sample links, replace with your’s

Now at the end I added a disable, enable button to control above links behavior.

Finally added jquery on page, don’t forget to add jquery library first. after that add below jquery code snippet.

In the above code as soon as you click on the Disable links it adds disable class on all given links and it converts itself in Enable button

If you click on any link with disable class then it’ll show you error message like link is disable. I used jquery hasClass() function to check whether disable class added on link or not. If disable class added then it’ll prevent normal action of anchor tag using jquery e.preventDefault() method.

Leave a Reply

Your email address will not be published. Required fields are marked *