Horje
What is HTML onmousedown Attribute

Definition and Usage

The onmousedown attribute fires when a mouse button is pressed down on the element.

Tip: The order of events related to the onmousedown event (for the left/middle mouse button):

  1. onmousedown
  2. onmouseup
  3. onclick

The order of events related to the onmousedown event (for the right mouse button):

  1. onmousedown
  2. onmouseup
  3. oncontextmenu

Applies to

The onmousedown attribute is part of the Event Attributes, and can be used on any HTML elements.

Elements Event
All HTML elements onmousedown

Browser Support

 


How to Execute a JavaScript when pressing a mouse button over a paragraph - HTML onmousedown Attribute

Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. The mouseUp() function sets the color of the text to green.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. The mouseUp() function sets the color of the text to green.
</p>

<script>
function mouseDown() {
  document.getElementById("p1").style.color = "red";
}

function mouseUp() {
  document.getElementById("p1").style.color = "green";
}
</script>

</body>
</html>

Output should be:

How to Execute a JavaScript when pressing a mouse button over a paragraph - HTML onmousedown Attribute




html onmousedown attribute

Related Articles
How to add HTML accept Attribute HTML Input HTML Attribute
How to add HTML accept-charset Attribute HTML Attribute
What is HTML accesskey Attribute HTML Attribute
What is HTML action Attribute HTML Attribute
What is HTML alt Attribute HTML Attribute
What is HTML async Attribute HTML Attribute
What is HTML autocomplete Attribute in HTML HTML Attribute
What is HTML autofocus Attribute HTML Attribute
What is HTML autoplay Attribute HTML Attribute
What is HTML charset Attribute HTML Attribute
What is HTML checked Attribute HTML Attribute
What is HTML cite Attribute HTML Attribute
What is HTML class Attribute HTML Attribute
What is HTML cols Attribute HTML Attribute
What is HTML colspan Attribute HTML Attribute
What is HTML content Attribute HTML Attribute
What is HTML contenteditable Attribute HTML Attribute
What is HTML controls Attribute HTML Attribute
What is HTML coords Attribute HTML Attribute
What is HTML data Attribute HTML Attribute
What is HTML data-* Attribute HTML Attribute
What is HTML datetime Attribute HTML Attribute
What is HTML controls Attribute HTML Attribute
What is HTML default Attribute HTML Attribute
What is HTML defer Attribute HTML Attribute
What is HTML dir Attribute HTML Attribute
What is HTML dirname Attribute HTML Attribute
What is HTML disabled Attribute HTML Attribute
What is HTML download Attribute HTML Attribute
What is HTML draggable Attribute HTML Attribute
What is HTML enctype Attribute HTML Attribute
What is HTML enterkeyhint Attribute HTML Attribute
What is HTML for Attribute HTML Attribute
What is HTML form Attribute HTML Attribute
What is HTML formaction Attribute HTML Attribute
What is HTML headers Attribute HTML Attribute
What is HTML height Attribute HTML Attribute
What is HTML hidden Attribute HTML Attribute
What is HTML high Attribute HTML Attribute
What is HTML href Attribute HTML Attribute
What is HTML hreflang Attribute HTML Attribute
What is HTML http-equiv Attribute HTML Attribute
What is HTML id Attribute HTML Attribute
What is HTML inert Attribute HTML Attribute
What is HTML inputmode Attribute HTML Attribute
What is HTML ismap Attribute HTML Attribute
What is HTML kind Attribute HTML Attribute
What is HTML label Attribute HTML Attribute
What is HTML lang Attribute HTML Attribute
What is HTML list Attribute HTML Attribute
What is HTML loop Attribute HTML Attribute
What is HTML low Attribute HTML Attribute
What is HTML max Attribute HTML Attribute
What is HTML maxlength Attribute HTML Attribute
What is HTML media Attribute HTML Attribute
What is HTML method Attribute HTML Attribute
What is HTML min Attribute HTML Attribute
What is HTML multiple Attribute HTML Attribute
What is HTML muted Attribute HTML Attribute
What is HTML name Attribute HTML Attribute
What is HTML novalidate Attribute HTML Attribute
What is HTML onabort Attribute HTML Attribute
What is HTML onafterprint Attribute HTML Attribute
What is HTML onbeforeprint Attribute HTML Attribute
What is HTML onbeforeunload Attribute HTML Attribute
What is HTML onblur Attribute HTML Attribute
What is HTML oncanplay Attribute HTML Attribute
What is HTML oncanplaythrough Attribute HTML Attribute
What is HTML onchange Attribute HTML Attribute
What is HTML onclick Attribute HTML Attribute
What is HTML oncontextmenu Attribute HTML Attribute
What is HTML oncopy Attribute HTML Attribute
What is HTML oncuechange Attribute HTML Attribute
What is HTML oncut Attribute HTML Attribute
What is HTML ondblclick Attribute HTML Attribute
What is HTML ondrag Attribute HTML Attribute
What is HTML ondragend Attribute HTML Attribute
What is HTML ondragenter Attribute HTML Attribute
What is HTML ondragleave Attribute HTML Attribute
What is HTML ondragover Attribute HTML Attribute
How to add HTML ondragstart Attribute HTML Attribute
What is HTML ondrop Attribute HTML Attribute
What is HTML ondurationchange Attribute HTML Attribute
What is HTML onemptied Attribute HTML Attribute
What is HTML onended Attribute HTML Attribute
What is HTML onerror Attribute HTML Attribute
What is HTML onfocus Attribute HTML Attribute
What is HTML onhashchange Attribute HTML Attribute
What is HTML oninput Attribute HTML Attribute
What is HTML oninvalid Attribute HTML Attribute
What is HTML onkeydown Attribute HTML Attribute
What is HTML onkeypress Attribute HTML Attribute
What is HTML onkeyup Attribute HTML Attribute
What is HTML onload Attribute HTML Attribute
What is HTML onloadeddata Attribute HTML Attribute
What is HTML onloadedmetadata Attribute HTML Attribute
What is HTML onloadstart Attribute HTML Attribute
What is HTML onmousedown Attribute HTML Attribute
What is HTML onmousemove Attribute HTML Attribute
What is HTML onmouseout Attribute HTML Attribute
What is HTML onmouseover Attribute HTML Attribute
What is HTML onmouseup Attribute HTML Attribute
What is HTML onmousewheel Attribute HTML Attribute
What is HTML onoffline Attribute HTML Attribute
What is HTML ononline Attribute HTML Attribute
What is HTML onpageshow Attribute HTML Attribute
What is HTML onpaste Attribute HTML Attribute
What is HTML onpause Attribute HTML Attribute
What is HTML onplay Attribute HTML Attribute

Single Articles
How to Execute a JavaScript when pressing a mouse button over a paragraph - HTML onmousedown AttributeHTML Attribute

Read Full:
HTML Attribute
Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded:
1 week ago
Uploaded by:
Admin
Views:
54


Reffered: https://www.w3schools.com/tags/att_onmousedown.asp

Share on: