Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:55:16+00:00 2026-06-11T13:55:16+00:00

I have a div (id=menu) on my page with onclick=toggledropdown(). This div has child

  • 0

I have a div (id=”menu”) on my page with onclick=”toggledropdown()”. This div has child img elements as well as text. The toggle code works just fine when anything but the images is clicked. However, when the images are clicked, the div slides down and then back up again.

toggle code:

function toggledropdown()
{
    if ($("#dropdown").is(":hidden"))
    {   
        $("#dropdown").slideDown(400);      
    }
    else
    {
        $("#dropdown").slideUp(50);     
    }
}

body.click to hide drop down if the page is clicked:

$(document.body).click(function(event)
{
    var targetID = $(event.target).attr("id");
    if (targetID !== "dropdown" && targetID !== "menu")
    {
        if (!$("#dropdown").is(":hidden"))
            toggledropdown();
    }
});

drop down.click to negate the body.click

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

The html div (some things unrelated to problem omitted):

<div class="menu" id="menu" onclick="toggledropdown();">
    <img id="dropdownthumbnail" (blahsrc/styleblah) />
    Text
    <img id="dropdownarrow" (blahsrc/styleblah) />
</div>

So, to reiterate, clicking on the menu div (minus the images) slides out the menu correctly, clicking on it again (including the images) or anywhere else on the page works correctly, but clicking on the images while the drop down is hidden toggles it twice (you can see it slide out and back in again).

Are the child imgs triggering the parent’s onclick twice? Once for the child, once for the parent? Why? How do I make it work as expected: clicking anywhere on the div triggers the onclick once?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:55:18+00:00Added an answer on June 11, 2026 at 1:55 pm

    You need to use event.stopPropagation to stop events from bubbling up.

    Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

    Which will prevent parent handlers from firing their events

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple menues on my page... <div class=menu> <div>Menu header</div> <div>Menu content</div>// should
I have a menu div which has a dark background. Inside it, I have
So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
I have the following jquery script: $(function(){ $('#top-menu').on('click', 'a.change-menu', function(e){ e.preventDefault() $(#menu-change-div).load($(this).attr(href)); }); });
I have menu bar and code is as follows <div style=background:#000; height: 25px;> <div
I have a nested menu with content divs that toggle onclick. By default, when
I have a dropdown type menu div with tags similar to below. this is
I have a page that has a menu and a content area. I dynamically
I have this code, it works for a rotating menu that is obviously a
I have following page in which there is a div menu. Inside menu we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.