2

i need to disable the anchor tag below.. am using this coding :( but it doesn't help me

jquery:-

$("a.lookupclick").addClass("viewDisabled");
$(".DeleteRow").addClass("viewDisabled");
$(".viewDisabled").prop('disabled', true);

or

$(".lookupclick").attr("disabled","disabled");

it works sometimes ,but most of the times it didn't works.. Y? how to prevent to click th

HTML :-

<div class="panel1">
  <a tabindex="1" disabled="" class="lookupclick" id="departmentpopup" href="#lookupform" >
     <img class="ImgSearch1" alt="Search" src="/Images/.jpg">
  </a>
</div>
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Padhu
  • 97
  • 3
  • 10
  • http://stackoverflow.com/questions/10276133/how-to-disable-html-links The CSS way is great in the most upvoted answer. jQuery's `addClass()` and `removeClass()` can be used when needed. CSS: `.disabled{cursor:not-allowed;} `.disabled > a{pointer-events:none;}` – ZZ-bb Apr 28 '15 at 12:13

4 Answers4

3

You could do:

$("a.lookUpClick").on("click", false);

And then:

$("a.lookUpClick").off("click");

to reactivate them.

Thank you Washington Guedes for the suggested 'golfing'!

Pudd
  • 449
  • 3
  • 13
  • 1
    you can just use: _$("a.lookUpClick").on("click", false);_ ... +1 for nice idea... here is a live example: _http://jsfiddle.net/oeppsk4n/_ –  Apr 28 '15 at 12:15
1

Try:

$("a.lookupclick").attr('href','');
madalinivascu
  • 32,064
  • 4
  • 39
  • 55
1

You can just prevent default function of the link:

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

If you want to know the difference between return false and preventDefault take a look at this question - event.preventDefault() vs. return false

Community
  • 1
  • 1
Pirozek
  • 1,250
  • 4
  • 16
  • 25
0

You can do this a couple of ways. You could listen for click events on the link and use the preventDefault() method to stop the event.

$('a.lookupclick').click(function(event){
    event.preventDefault();
});

Another option is that you can make the href attribute of the links javascript:; which will cause the links to be clickable but not do anything. If you need to do this with jQuery you could do it as such:

$('a.lookupclick').attr('href','javascript:;');
Mike Hamilton
  • 1,519
  • 16
  • 24