Bind an event handler to the “contextmenu” Javascript event using jQuery.

$("body").contextmenu(function (e) {
 
});

This captures any Right Click event happening through out the web page.

Now if you want to handle Right Click on a particular element, you can do so by doing something like this:

$("body").contextmenu(function (e) {
 var clickedElement = e.target;
 
 //check if it's a particular element of interest by looking at it's id or class
 //..
});

 

Last modified: September 14, 2018

Author