I want to stop propagate event from parent div
to child div
in my html. Here a simple code what I\'m trying to do:
The accepted answer is correct but in a best scenario when you have multiple nested elements, You would like to not cancel the event but to get the actual clicked parent container and work with it.
$('.clicked-container').click((e) => {
let t = e.target;
while (!$(t).hasClass( "clicked-container" )) { t = t.parentNode; }
...
$(t).toggleClass('active-or-whatever-you-want');
});
Also "this" in the accepted answer doesn't refer anymore to the same thing when you using Arrows => in ES6