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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:03:57+00:00 2026-06-03T07:03:57+00:00

I tried using the code below to set up a contextmenu which only displays

  • 0

I tried using the code below to set up a contextmenu which only displays when the container div is clicked. But I am pretty messed up. If it helps here is the fiddle http://jsfiddle.net/PhilippB/SMKMW/1/.

var container = document.getElementById("container");
var contextmenu = document.getElementById("contextmenu");

container.onclick = function() {contextmenu()} ;
contextmenu.style.display = "none";

function contextmenu(event) {
    if (contextmenu.style.display == "none") {
        contextmenu.style.display = "block";
        contextmenu.style.left = event.pageX + "px";
        contextmenu.style.top = event.pageY + "px";
    }
    else {
        contextmenu.style.display = "none";
    }
}​
  • 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-03T07:03:58+00:00Added an answer on June 3, 2026 at 7:03 am

    You have a couple of strange things going on, so it isn’t entirely clear to me what you’re after.

    • You have 2 different variables named ‘contextmenu’. The first is when you do a getElementById, the second when you define the contextmenu function.
    • Your JS Fiddle example doesn’t match your example above, and it contains an error in the IF statement (you only use 1 = not 2). In fact, your JSFiddle example is very different from your above example
    • In your example, the only content inside container is contextmenu, but you start it off with display: none, so it’s hard to know what to click to get it to show.

    Try this updated version of your JSFiddle (http://jsfiddle.net/SMKMW/2/)

    var container = document.getElementById("container");
    var contextmenuElement = document.getElementById("contextmenu");
    
    container.onclick = function() {contextmenu()} ;
    contextmenuElement.style.display = 'none';
    
    function contextmenu(event) {
    
        var container = document.getElementById("container");
    
        if (contextmenuElement.style.display == "block") {
            contextmenuElement.style.display = "none";
        }
        else {
            contextmenuElement.style.display = "block";
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried accessing web for xml parsing using the code below: System.Uri proxy =
i've tried using this code and this to make a random quote generator, but
I am using the below code to instantiate a 9patch image and set it
I was using the code below, when user_id wasnt set as unique and it
I am using the code below to set my two NSArray ivars: The issue
Update: I have tried Sheldon's code below but I have struck a couple of
I tried using the following code in .java(main activity): final ImageView diskView1 = (ImageView)
Have you tried using MVC or any other UI pattern for GWT client code.
I tried to place a photo frame (image) on a picture using code <Canvas>
I'm trying to drop a SQL Server database from .NET code. I've tried using

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.