We can prevent right-clicking on any element by attaching the event listener to that specific element and calling event.preventDefault() again. Let us see an example of HTML oncontextmenu event Attribute −. oncontextmenu: This attribute fires at the time when a context menu is triggered by the user through the right-click on the element. Demo. any. The value of the contextmenu attribute is the id of the element to open. This is useful for building controlled components. Name. The event attribute oncontextmenu allows you to set the script to trigger when the context menu on the element is called. The typemustmatch is a boolean attribute. HTML attributes are special words used inside the opening tag to control the element's behaviour. CSS to put icon inside an input element in a form. There is no specific attribute present to be used with the