A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-dom-onmousedown-event/ below:

HTML DOM onmousedown Event - GeeksforGeeks

HTML DOM onmousedown Event

Last Updated : 12 Jul, 2025

The HTML DOM onmousedown event occurs when a mouse button is pressed over an element. It's useful for implementing interactive features that respond to mouse clicks or taps on web elements.

Syntax:

<element onmousedown="myScript">
object.onmousedown = function(){myScript};
object.addEventListener("mousedown", myScript);

Related events for left-click: 

Related events for right-click: 

HTML DOM onmousedown Event Examples

Example: In this example we demonstrating the onmousedown event. When mouse button is pressed over "HTML DOM onmousedown Event", text changes to "button pressed.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
      HTML DOM onmousedown Event
  </title>
</head>

<body>
        <h2 id="try">
          HTML DOM onmousedown Event
      </h2>

        <script>
            document.getElementById(
              "try").addEventListener(
              "mousedown", btnpressed);

            function btnpressed() {
                document.getElementById(
                  "try").innerHTML = 
                  "button pressed.";
            }
        </script>
</body>

</html>

Output: 

HTML DOM onmousedown Event Example Output Supported Browsers

The browsers supported by HTML DOM onmousedown Event are listed below: 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4