jQuery contextmenu() Method
Examples
Right-click triggers the contextmenu event
<div id="target">
Right-click here
</div>
<script>
$(function () {
$( "#target" ).contextmenu(function() {
alert( "The .contextmenu() handler is called." );
});
})
</script>
Try it Yourself »
Definition and Usage
The contextmenu() function is used to add an event handler to the contextmenu event.
Note:The .contextmenu() method is just a shorthand for .on( "contextmenu", handler ), and you can use .off( "contextmenu" ) to remove this event.
Syntax
$(selector).contextmenu( [eventData ], handler )
| Parameters | Description |
|---|---|
| eventData | Optional. Any type. An object of parameters to pass to the event handler. |
| handler | Optional. Function type. The function to execute when the event is triggered. |
More Examples
Right-click to display an alert
When the paragraph element is triggered, it displays "Hello World!".
Right-click to toggle background color
Right-click to toggle the background color.
Other Extensions
jQuery Event Methods