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 6957031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:56:49+00:00 2026-05-27T14:56:49+00:00

I have number of drop down menu’s which gets called with a onClick event

  • 0

I have number of drop down menu’s which gets called with a onClick event right below those specific div’s,and i also have a window.onclick set inorder to retract those dropdowns(which are active) when a user clicks elsewhere.

Now,when i click on a div(which has a dropDown) the drop down is getting activated(menu gets created) and simultaneously retracting (because of the window.click )

The menu’s are getting created and getting destroyed at the same time!,Any work arounds to perform the window.onclick iff the clicked element is not on of the div’s with a dropdown??

Silly question,from a beginner..
thanks in advance!!

here’s a sample code!!.. the onclick on the div is supposed to bring out the menu — and the window.onclick is supposed to retract the menu(all he menu’s which are expanded)

<html>
    <style type="text/css">
    .bar{
    width: 30px;
    height: 30px;
    background-color: black;
    display: none;
    }
    </style>
    <script type="text/javascript" >
    function fire(){
    document.getElementById("bar").style.display="block";
    }
    window.onclick=unfire;
    function unfire(){
    if(document.getElementById("bar").style.display== "block")
    document.getElementById("bar").style.display="none";
    }
    </script>
    <input type="button" value="foo" onclick="fire()">
    <div id="bar" class="bar"></div>
    </html>

Edit:added the code sample

  • 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-05-27T14:56:49+00:00Added an answer on May 27, 2026 at 2:56 pm

    this will happen because of a mechanism called “Event bubbling”, which will likely not just firing your event for the specific DOM element, but will also continue to raise your event from your child DOM element(s), until it reach the very beginning of your page.

    using jquery library for example, provides us with a method to prevent this default action from happening (event.stopPropagation() ).

    I don’t know exactly if native JS code can achieve the same behavior, but let me know if you can use jQuery, and I will provide you with code example.

    thanks,

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

Sidebar

Related Questions

I have a button which appends a drop down menu to the site, and
I have the following drop down menu: <select id=target> <option value=0>Zero ($123.45)</option> <option value=1>One
I have a page with several multiselect drop-down menus. Each menu has a general
I have a normal WinForms ToolStripDropDownButton's drop down menu that is populated dynamically. In
within an asp.net page I have a predefined drop down menu <asp:DropDownList CssClass=queryterm dropdownSpacer
I have an HTML page (index.php) with a drop down menu that contain numbers
I have a range of items in an HTML drop-down menu that I need
I'm busy to create an online agenda. I have 3 drop down menu's where
I'm trying to insert a drop down menu values to a table named units
I'm using spark List s and PopupAnchor s to build a drop down menu

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.