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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:38:15+00:00 2026-05-26T11:38:15+00:00

I have a silly (and hopefully easily fixed) problem, which I will now attempt

  • 0

I have a silly (and hopefully easily fixed) problem, which I will now attempt to describe.

The scenario-> I am trying to create a context menu using HTML / CSS / JS. Just a DIV with a high z-order that appears where a user right-clicks. Simple, and that portion works. The portion which does not is my attempt to make the menu disappear if the user clicks somewhere where a context menu is not supported; I am attempting to achieve this end with a general function in the BODY tag that fires onclick. Since the BODY tag is given a z-order of -1, and any other tags which might trigger the context menu to appear are given a higher z-order value, my hope was that if I right-clicked an element with a z-order of, say, 3, then it would fire the showMenu() function; instead, it appears that it does this, as well as passes the event to the underlying BODY tag, which causes the menu to become hidden again.

As you might imagine, it is incredibly frustrating. Does anyone know how to make prevent events from being passed down? (The INPUT button is what you may want to look at, the A anchor is something similar, but not coded to work just yet).

Here’s the HTML code:

http://pastebin.com/YeTxdHYq

And here’s my CSS file:

http://pastebin.com/5hNjF99p

This appears to be a problem with IE, Firefox, and Chrome.

  • 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-26T11:38:16+00:00Added an answer on May 26, 2026 at 11:38 am

    A lot of DOM events “bubble” from the bottom object up through container objects, which means they’ll eventually reach the body. But you can stop this – try adding the following code to the click handler on your element:

    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    

    …where e is the variable you already have in your function representing the event object.

    event.stopPropagation(); should work in modern browsers, but the old IE way was event.cancelBubble = true; – to be safe you can just do both (but as shown above check that .stopPropagation is defined before trying to call it).

    With the above code added, if you click on the element your function will stop container objects (include the body) from seeing the click. If you click somewhere else your function isn’t called so then the body will process the click.

    There’s more info about this at MDN and QuirksMode.org.

    Note: I’ve ignored the z-order issue because in this case I think it is a non-issue – all elements are descendents of the body so (unless you stop it) I would expect events to bubble to the body regardless of z-order.

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

Sidebar

Related Questions

HI, I have the following scenario which I will try to explain as best
I have a (hopefully silly) iPhone programming question. I'm trying to get a string
I have a silly, little class FileSystemSize which can be used both as an
I have a really silly problem that has cost me a load of time
I have a question which may be somewhat silly because I'm pretty sure I
Here I am asking more silly graphics questions. Hopefully soon I will leave the
I have a silly problem i haven't been able to figure out. Can anyone
I have a silly problem with Twitterizer2 and probably me :) . I add
I have a silly question which prevents me to proceed with my project. My
Please excuse (or improve the title) but I have a silly little problem that's

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.