HTML global attribute contextmenu








The contextmenu attribute installs a context menu for an element.

The context menu appears when a user right-clicks on the element.

The value of the contextmenu attribute is the id of the <menu> element to open.

What's new in HTML5

The contextmenu attribute is new in HTML5.

Syntax

<element contextmenu="menu_id">

Attribute Values

menu_id
The id of the <menu> element

Browser compatibility

contextmenu No No Yes No No




Example

<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- w  ww  .j a va2 s  .co  m-->
    background: yellow;
    border: 1px solid #cccccc;
    padding: 10px;
}
</style>
</head>
<body>

<div contextmenu="mymenu">
    <p>Right-click inside this box to see the context menu!</p>
    
    <menu type="context" id="mymenu">
      <menuitem label="Refresh from custom menu" onclick="" icon=""></menuitem>
    </menu>

</div>


</body>
</html>

Click to view the demo