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?
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.
e.cancelBubble = true as well, or does jQuery handle this?Use event.stopPropagation or event.stopImmediatePropagation to prevent the event from bubbling.