10

this is an active link

<a href="#" class="btn btn-large">Link</a>

how to disable this link using javascript, so the code would be like this?

<a href="#" class="btn btn-large disabled">Link</a>
3
  • In response to what you want it to be disabled? Commented Jul 12, 2013 at 8:05
  • to prevent the savechanges button clicked when data values not yet edited Commented Jul 12, 2013 at 8:14
  • Might be a duplicate of the question What is the easiest way to disable/enable buttons and links (jQuery + Bootstrap), asked two months before this. Commented Jul 29, 2015 at 2:59

2 Answers 2

18

HTML

<a href="#" id="myLink" class="btn btn-large">Link</a>

Pure JS

var d = document.getElementById("myLink");
d.className = d.className + " disabled";

jQuery

$('#myLink').addClass('disabled');
Sign up to request clarification or add additional context in comments.

2 Comments

Notice that with this the button will just appear disabled but will still be clickable. To also make it unclickable, you can add this (jQuery): $('#myLink').on('click', function(e) { e.preventDefault(); });
In modern browsers and modern bootstrap, this code will not necessary because the .btn:disabled has pointer-events:none so it will not be clickable.
-2

Use the attribute disabled in a class, like class="btn btn-danger disabled"

For example:

<a href="exampleLink.php?id=3&amp;option=1" class="btn btn-danger disabled" role="button">Cancelar</a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.