Right-click here
Easy Tutorial
❮ Jquery Chaining Misc Extend ❯

jQuery contextmenu() Method

jQuery Event Methods

Example

Trigger the contextmenu event by right-clicking

<div id="target">
    Right-click here
</div>
<script>
$(function () { 
    $( "#target" ).contextmenu(function() {
        alert( "Handler for .contextmenu() called." );
    });
})
</script>

Definition and Usage

The contextmenu() function is used to add an event handler to the contextmenu event.

Note: The .contextmenu() method is a shorthand for .on( "contextmenu", handler ), and can be removed using .off( "contextmenu" ).

Syntax

Parameter Description
eventData Optional. Any type An object of data to pass to the event handler.
handler Optional. Function type The function to execute when the event is triggered.

More Examples

Right-click to show a tooltip

Right-click to toggle background color


jQuery Event Methods

❮ Jquery Chaining Misc Extend ❯