Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to add disabled class to bootstrap anchor button, but it does not work. I added it like below,

  1. jquery>js>html
  2. jquery>html>js

$(document).ready(function() {
  var fewSeconds = 5;
  
  $('#dis').click(function() {
    var btn = $('#dis');
    btn.addClass('disabled');
    // alert('works');
    
    setTimeout(function() {
      btn.removeClass('disabled');
    }, fewSeconds * 1000);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="/posts" id="dis" class="btn btn-light me-2 my-2 rounded-pill" type="button">Posts</a>
question from:https://stackoverflow.com/questions/65559595/disable-link-button-in-laravel-after-click

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
499 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use preventDefault(); to disable the link.

$(document).ready(function() {
  $('.disabled').on("click", function (e) {
    e.preventDefault();
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<a href="https://stackoverflow.com/" class="disabled">Link</a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...