zhangyx007
zhangyx007

Reputation: 35

Bubbling events in IE

all Now I defined a change click for checkbox,when chexkbox checked,I will show a tips,I also defined click in my HTML ,when I click everywhere,I will hide a tips,but my problem is When I checked the checkbox,the tips is not show in IE,I through debugger,I find the Body click is Trigger,is it a Bubbling events?I try write

window.event ? window.event.cancelBubble = true : e.stopPropagation();

,but it is not work,body click still Trigger in IE,in Google isn’t have this problem,how to deal with it?

$(document).on("change", ".checked", function (self) {
   $(".circle_bot").show();
   window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
               
$("body").click(function () {
        $(".circle_bot").hide();
    });
<body>
  ...
  <div class="circle_bot"></div>
  ...
<input type="checkbox" class="checked"/>
</body>

I want to only trigger check click,isn't trigger body click when chenced the checkbox.

Upvotes: 2

Views: 53

Answers (1)

charlietfl
charlietfl

Reputation: 171669

You can check what target of click was and do something like:

$("body").click(function(event) {
  // don't do anything if checkbox clicked
  if (!$(event.target).is('.checked')) {
    $(".circle_bot").hide();
  }
});

note that jQuery provides event object in all event handlers so you don't have to see if window.event is available, it is done for you

Upvotes: 2

Related Questions