W3Schools.com

onmousedown Event

Event Object Reference Event Object

Example

Execute a JavaScript when pressing a mouse button over a paragraph:

<p onmousedown="mouseDown()">Click the text!</p>

Try it yourself »
(more examples at the bottom of this page)

Definition and Usage

The onmousedown event occurs when a user presses a mouse button over an 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

Syntax

In HTML:

<element onmousedown="SomeJavaScriptCode">

In JavaScript:

object.onmousedown="SomeJavaScriptCode"

Parameter Description
SomeJavaScriptCode Required. Specifies a JavaScript to be executed when the event occurs


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The onmousedown event is supported in all major browsers.


onmousedown is Supported by the Following HTML Tags:

<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, <caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, <li>, <map>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>

onmousedown is Supported by the Following JavaScript objects:

Document, Window


Examples

Try it Yourself - Examples

Alert which mouse button that was pressed
Alert which mouse button the user pressed.

Alert the element the user clicked on
Alert the name of the element the user clicked on.


Event Object Reference Event Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE