0

I am struck with a problem. I need to know whether or not the context menu is hidden or not. I am not using any kind of plugin for the context menu.

What I did to fix this is when I right click and open the context menu (default) I make

contextMenuVisible = true

while this menu is open and I click anywhere else the menu gets hidden, but in this click the click event handler is not called. But I need to set contextMenuVisible to false.

May be this is a wrong approach to solve the issue, if so please tell me the way to achieve this. Please help.

Krupal Shah
  • 8,949
  • 11
  • 57
  • 93

2 Answers2

1

You can use the hidden selector:

// Matches all elements that are hidden
$('element:hidden')

You can use it in your jquery

var isHidden = $('#myDiv').is(':hidden');

Check the value of isHidden for checking visibility.

Anju Aravind
  • 3,262
  • 2
  • 16
  • 22
  • I am not using any plugin. I am talking about the browser's own context menu that appears on right click. I need to know the visibility of that. Or some way so that I can set contextMenuVisible to false just like I set it to true when the context menu opens. – Sachin W Aug 18 '14 at 08:36
  • @SachinW what do you need to do when the context menu is visible/hidden? – jasonscript Aug 18 '14 at 08:46
  • @jasonscript I have a textarea that is created on pressing tab from a input field. In that textarea I have bind an event, on pressing ESC it removes that textarea, but if the user has opened the context menu then on ESC it will hide the menu first then on again pressing ESC it will remove the textarea. It works fine until I click somewhere else when the context menu is opened. On doing so the menu gets hidden but the handler is not called so the context menu is not visible but still the user has to press the ESC key 2 times, because contextMenuVisible is set to true for the first time. – Sachin W Aug 18 '14 at 09:26
  • @AnjuRaghunath that is a way. But I want to know why this is not working. – Sachin W Aug 18 '14 at 14:53
0

Here is a way to distinguish between mouse clicks. check here

fiddle

And i think this one will work for you.

$('.element').bind("contextmenu",function(e){
       alert('Context Menu event has fired!');
       return false;
    }); 
Community
  • 1
  • 1
Anju Aravind
  • 3,262
  • 2
  • 16
  • 22