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";
}
}
You have a couple of strange things going on, so it isn’t entirely clear to me what you’re after.
getElementById, the second when you define thecontextmenufunction.=not 2). In fact, your JSFiddle example is very different from your above examplecontaineriscontextmenu, but you start it off withdisplay: 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/)