SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

What's the difference between onMouseDown and onClick

Altcademy Team wrote on 7 February 2018

I am starting to see people use onMouseDown instead of onClick. What's the difference between the two and why would I want to use onMouseDown instead.

Answer
Here is the event order of the left mouse click
  1. onmousedown
  2. onmouseup
  3. onclick
You would use onMouseDown if you want to preventDefault as soon as the user clicks on a button. This is preferred in a texteditor where you want to keep the focus on the input while clicking on buttons that change the styles of the text.

Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026