Html- how to disable <a href>?

sarit rotshild picture sarit rotshild · Feb 4, 2015 · Viewed 177.7k times · Source

I created a button that open a modal window on click.

<a href="#"  data-toggle="modal" data-target="#myModal" class="signup-button gray-btn pl-pr-36" id="connectBtn"  data-role="disabled">Connect</a>

For some reason the data-role="disabled" doesn't work good. How can I disable it?

Answer

iivannov picture iivannov · Feb 4, 2015

You can use CSS to accomplish this:

.disabled {
  pointer-events: none;
  cursor: default;
}
<a href="somelink.html" class="disabled">Some link</a>

Or you can use JavaScript to prevent the default action like this:

$('.disabled').click(function(e){
    e.preventDefault();
})