Window Click Event Is Getting Called Twice
I have an click event on window. There is also a checkbox and a label for the checkbox. When you click on the label, the window's click event gets called twice, once for the checkb
Solution 1:
The event bubbles up. To stop that, use the stopPropagation()
method:
var checkbox = document.getElementById('checkbox-id');
window.addEventListener('click', function(e) {
console.log(checkbox.checked, e.target)
e.stopPropagation();
});
For more details on event order and bubbling: http://www.quirksmode.org/js/events_order.html
Post a Comment for "Window Click Event Is Getting Called Twice"