How do you make an anchor link non-clickable or disabled?

后端 未结 18 1888
清酒与你
清酒与你 2020-11-27 02:38

I have an anchor link that I want to disable once the user clicks on it. Or, remove the anchor tag from around the text, but definitely keep the text.



        
相关标签:
18条回答
  • 2020-11-27 03:17
    $('a').removeAttr('href')
    

    or

    $('a').click(function(){ return false})
    

    It depends on situation

    0 讨论(0)
  • 2020-11-27 03:17

    This is the method I used to disable.Hope it helps.

    $("#ThisLink").attr("href","javascript:;");
    
    0 讨论(0)
  • 2020-11-27 03:20

    Simply in SASS:

    .some_class{
         // styles...
    
         &.active {
           pointer-events:none;
         }
    }
    
    0 讨论(0)
  • 2020-11-27 03:21
    $('#ThisLink').one('click',function(){
      $(this).bind('click',function(){
        return false;
      });
    });
    

    This would be another way to do this, the handler with return false, which will disable the link, will be added after one click.

    0 讨论(0)
  • 2020-11-27 03:23

    Just remove the href attribute from the anchor tag.

    0 讨论(0)
  • 2020-11-27 03:25

    Add a css class:

    .disable_a_href{
        pointer-events: none;
    }
    

    Add this jquery:

    $("#ThisLink").addClass("disable_a_href"); 
    
    0 讨论(0)
提交回复
热议问题