Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery click with nested div

Tags:

jquery

I have a div and when I click, it opens a menu. In that div i have a nested div, and when I click on, it opens the same menu which is also logical.

Now I want when I press the nested div it doesn't open the menu.

How can I do that?

like image 648
Leon van der Veen Avatar asked Jul 17 '26 15:07

Leon van der Veen


1 Answers

You can bind a click event handler to the inner div and stop the propagation of the event there:

$("#innerDiv").click(function(e) {
    e.stopPropagation();
});

That will prevent the event from bubbling up to the parent element, where it would cause the click event handler bound to it to fire.

like image 119
James Allardice Avatar answered Jul 19 '26 04:07

James Allardice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!