I have a button that has a style
pointer-events: none;
And this button has a parent element that performs a collapsible event. I don't know how to prevent this button from triggering its parent elements collapsible event. This is caused because of the button style which is pointer-events: none
Thanks
The event. stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent event handlers from being executed.
stopPropagation()Returns: undefined. Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
preventDefault() prevents the browsers default behaviour, but does not stop the event from bubbling up the DOM. The event. stopPropagation() prevents the event from bubbling up the DOM, but does not stop the browsers default behaviour.
Assuming the following html:
<div class="collapsible">
<button>Hi</button>
</div>
You could do something like this:
$('.collapsible').click(function(e) {
if ($(this).children('button').css('pointer-events') == 'none') return;
//do collapse
});
or maybe this:
$('.collapsible').click(function(e) {
//do collapse
});
$('.collapsible button').click(function(e) {
if ($(this).css('pointer-events') == 'none')
e.stopPropagation();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With