--- title:
context
: The context menu state, which represents a group of commands activated through another element. This might be through the {{htmlattrxref("menu", "button")}} attribute of a {{HTMLElement("button")}}, or an element with a contextmenu
attribute. When nesting {{HTMLElement("menu")}} elements directly within one another, this is the missing value default if the parent is already in this state.list
: The list menu state, which represents a series of commands for user interaction. This is the missing value default, except where the parent element is a {{HTMLElement("menu")}} in the context menu state.<!-- A button, which displays a menu when clicked. --> <button type="menu" menu="dropdown-menu"> Dropdown </button> <menu type="context" id="dropdown-menu"> <menuitem label="Action"> <menuitem label="Another action"> <hr> <menuitem label="Separated action"> </menu>
{{EmbedLiveSample('Example_1')}}
<!-- A context menu for a simple editor, containing two menu buttons. --> <menu> <li> <button type="menu" value="File" menu="file-menu"> <menu type="context" id="file-menu"> <menuitem label="New..." onclick="newFile()"> <menuitem label="Save..." onclick="saveFile()"> </menu> </li> <li> <button type="menu" value="Edit" menu="edit-menu"> <menu type="context" id="edit-menu"> <menuitem label="Cut..." onclick="cutEdit()"> <menuitem label="Copy..." onclick="copyEdit()"> <menuitem label="Paste..." onclick="pasteEdit()"> </menu> </li> </menu>
{{EmbedLiveSample('Example_2')}}
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'interactive-elements.html#the-menu-element', '<menu>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5.1', 'interactive-elements.html#the-menu-element', '<menu>')}} | {{Spec2('HTML5.1')}} | Initial definition |
{{Compat("html.elements.menu")}}
contextmenu
global attribute can be used on an element to refer to the id
of a menu
with the context
{{htmlattrxref("type","menu")}}.