On Jan 18, 4:07 pm, Legostrat <[email protected]> wrote:
> <div id="button">
> Click here
> <div id="submenu">
> option 1
> option 2
> </div>
> </div>
>
> So, when you click on the button div, it reveals the sub-menu div.
> The problem is that when you click on the content within the sub-menu
> it activates the .click action attached to the button div.
I didn't go to the live site, but if your markup is as simple as that
(i.e. "Click here" is directly in the outer div) then this might be
all you need:
$("#button").click(function(event) {
if (event.target.id != "button") return;
$("#submenu").toggle();
});
If the click here is nested deeper, you might need something more like
this:
$("#button").click(function(event) {
if ($(event.target).closest("#submenu").length) return;
$("#submenu").toggle();
});
The idea is simply to ignore those events that are inside the submenu.
Cheers,
-- Scott