Vipul sharma
Vipul sharma

Reputation: 1255

how to make html anchor tag not click able with jquery?

I have html like this (note -: I included j library on the top of page )

 <div class="WIWC_T1">
    <a href="javascript:void(0);" onClick="call_levelofcourse();popup('popUpDiv1')">Level of Course</a>
 </div>

to make it not clickable i used jquery like this

$(".WIWC_T1 a").click(function(){
    return false ;
});

i tried this too

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

but onClick="call_levelofcourse();popup('popUpDiv1')" is still working on my page . what is soltuion to do it in very simple way ??

Upvotes: 0

Views: 6679

Answers (6)

Nicolai
Nicolai

Reputation: 1953

Another aproach (which not uses jQuery) is to use css class:

.disable-anchor{
  pointer-events: none;
  cursor: default;
}

and then just add this class to your anchor like:

<a href="javascript:void(0);" 
   class="disable-anchor"     
   onClick="call_levelofcourse();popup('popUpDiv1')">
    Level of Course
</a>

P.S. check the availability of pointer-events before using it because this is the CSS3 feature.

Upvotes: 4

Zander
Zander

Reputation: 1086

To prevent events, like a when clicking, prevent that event like this:

$(".WIWC_T1").on("click", function(e)) {
    e.preventDefault();
    //Do your code, such show a popup
}

Upvotes: 1

Vimal Vataliya
Vimal Vataliya

Reputation: 260

 $(".WIWC_T1 a").removeAttr('onclick');

Upvotes: 0

Vivek Gupta
Vivek Gupta

Reputation: 1055

$(".WIWC_T1 a").on("click", function(){ 
   $(this).attr("onClick", false); 
});

Please remember to add Jquery prototype Thanks Vivek

Upvotes: 0

v.orujov
v.orujov

Reputation: 56

<a href="javascript:void(0);" onClick="call_levelofcourse();popup('popUpDiv1')" class="unclickable">Level of Course</a>



function call_levelofcourse(){
if(!$("a").hasClass("unclickable")){
 /* your codes here */
}
}

Upvotes: 0

Janitha Tennakoon
Janitha Tennakoon

Reputation: 906

Try this

$(".WIWC_T1 a").click(false);

Upvotes: 1

Related Questions