javascript - Prevent parent event fire on Jquery -
I have a lot of trouble in my code.
When I change a checkbox status, the click event also fires in the form of parents as I have tried various ways to solve this problem:
-
event.stopImmediatePropagation ();
event.stopPropagation ()
event.preventDefault ();
Return false
Unfortunately, no one does the work (probably not related to the "Event Widening" issue is).
HTML
& lt; Div class = "sortable" & gt; & Lt; Span & gt; Hello All! & Lt; / Span & gt; & Lt; Br / & gt; & Lt; Label & gt; Click me & lt; Input type = "checkbox" check = "check" /> & Lt; / Label & gt; & Lt; / Div & gt;
jQuery
$ (function () {$ ('. Sortable input [type = checkbox]'). ( Event (events) {event.stopImmediatePropagation (); event.stopPropagation (); event.preventDefault (); Warning ('checkbox changed');}); $ ('. Sortable') Click (function () {warning ('Sorted Click');});});
You can find the code at:
As you have Click on the parent's divan to interrupt the event, it is also firing. You can see the target element when the 'checkbox is not present' in the handheld pentant click event.
$ ('sortable' ). Click (function (event) {if (event.target. Type! = "Checkbox") console.log ('sortable clicked');});
Comments
Post a Comment