最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to make html anchor tag not click able with jquery? - Stack Overflow

programmeradmin3浏览0评论

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 ??

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 ??

Share Improve this question edited Feb 13, 2015 at 7:24 Vipul sharma asked Feb 13, 2015 at 6:48 Vipul sharmaVipul sharma 1,2551 gold badge14 silver badges34 bronze badges 3
  • remove onClick from a – Rajashekhar Rangappa Commented Feb 13, 2015 at 6:50
  • no i cant remove onclick function ... from a tag line – Vipul sharma Commented Feb 13, 2015 at 6:54
  • 1 This answer should help stackoverflow./a/825193/16959 – Jason Sperske Commented Feb 13, 2015 at 6:54
Add a ment  | 

6 Answers 6

Reset to default 4

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.

Try this

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

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
}
<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 */
}
}
$(".WIWC_T1 a").on("click", function(){ 
   $(this).attr("onClick", false); 
});

Please remember to add Jquery prototype Thanks Vivek

 $(".WIWC_T1 a").removeAttr('onclick');
发布评论

评论列表(0)

  1. 暂无评论