Skip to content
Related Articles

Related Articles

HTML | oncontextmenu Event Attribute

View Discussion
Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 16 Aug, 2022
View Discussion
Improve Article
Save Article

This attribute works when the user right-clicks on an element to open the context menu.
Supported Tags: 

  • It supports all HTML elements.


<element oncontextmenu="script">

Attribute Value: This attribute contains single value script. The script to be run when oncontextmenu attribute called. It is supported by all HTML elements.
Note: This attribute is new in HTML 5.


<!DOCTYPE html>
        <title>oncontextmenu Event Attribute</title>
            div {
                background: Green;
                border: 1px solid black;
                padding: 10px;
            h1 {
        <h2>oncontextmenu Event Attribute</h2>
        <div oncontextmenu="myFunction()" contextmenu="mymenu">
<p>Right-click inside this box</p>
            function myFunction() {
                alert("You right-clicked inside the div!");



Supported Browsers: The browser supported by oncontextmenu attribute are listed below: 

  • Chrome 1
  • Edge 12
  • Internet Explorer 9
  • Firefox 6
  • Safari 3
  • Opera 10.5


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!