Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery contextmenu() method

jQuery contextmenu() method

jQuery event methods jQuery event methods

Example

Right-click to trigger the contextmenu event

<div id="target">

Right-click here

div

<script$(function(){$("#target" )>

.

contextmenu

(

function

(

)

{

alert

(

"

The .contextmenu() handler is called.

"

)

;

}

)

;

}

)

script

Try it »


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 the event can be removed with .off( "contextmenu" ).

Syntax

$

(selector).contextmenu( [eventData ], handler )

Parameters Description
eventData Optional. Any type. A parameter object passed to the event handler.
handler Optional. Function type. The function executed when the event is triggered.

More examples

Right-click to show a popup
When the paragraph element is triggered, display "Hello World!".

Right-click to toggle the background color
Right-click to toggle the background color.


jQuery event methods jQuery event methods