click on link should not trigger parental onclick-event

前端 未结 4 1569
长发绾君心
长发绾君心 2021-01-13 17:38

I\'ve got the following code:


                      
相关标签:
4条回答
  • 2021-01-13 18:01
    $(function (){
      $('#link').click(function (e){ e.stopPropagation(); /*do other thing*/});
    })
    
    0 讨论(0)
  • 2021-01-13 18:01

    Use the unbind http://api.jquery.com/unbind/

    0 讨论(0)
  • 2021-01-13 18:03

    OnClick event you can pass the current object type. something like

    onclick=foo(this)

    The function foo looks like

     function foo(obj) {    
          if(obj.tagName != 'A') {
           alert('Yes')    
          } 
    }
    
    0 讨论(0)
  • 2021-01-13 18:14

    Add a click handler to your link and stop event bubbleing to the parent div. Like this:

    $('#link').click(function(e) {
      e.stopPropagation();
    });
    
    0 讨论(0)
提交回复
热议问题