jQuery Tutorial Tutorials - jQuery .contextmenu() method

jQuery .contextmenu() method

The .contextmenu() method in jQuery is used to bind an event handler to the contextmenu event on the element
or trigger an contextmenu event on an element.

jQuery .contextmenu() method Syntax

.contextmenu()
.contextmenu(handler)
.contextmenu(eventData,handler)
Parameter Type Description
handler Function A function to execute when the contextmenu is triggered on the matched element.
return false to prevent the default right click action.
eventData Anything Additional data passed to the event handler.

jQuery .contextmenu() method Example

Call .contextmenu() without an argument will trigger a contextmenu event.

example

Trigger the contextmenu event on all paragraphs:

$("p").contextmenu();

jQuery .contextmenu([eventData,]handler) method Example

example

Right click to toggle background color.

$("#block").contextmenu( function () { 
    $(this).toggleClass( "highlight" );
    // return `false` to prevent the default right click action
    return false;
});            
Date:2019-08-29 23:58:20 From:www.Lautturi.com author:Lautturi