How do I prevent a parent's onclick event from firing when a child anchor is clicked?

后端 未结 22 1364
旧巷少年郎
旧巷少年郎 2020-11-22 00:37

I\'m currently using jQuery to make a div clickable and in this div I also have anchors. The problem I\'m running into is that when I click on an anchor both click events ar

22条回答
  •  伪装坚强ぢ
    2020-11-22 01:12

    add a as follows:

    ....
    

    or return false; from click handler for #clickable like:

      $("#clickable").click(function() {
            var url = $("#clickable a").attr("href");
            window.location = url;
            return false;
       });
    

提交回复
热议问题