ใช้แอตทริบิวต์ onmousedown ใน HTML เพื่อรันสคริปต์เมื่อกดปุ่มเมาส์ลงบนองค์ประกอบ
ตัวอย่าง
ลองรันโค้ดด้านล่างเพื่อใช้งานแอตทริบิวต์ onmousedown:
<!DOCTYPE html>
<html>
<body>
<h3 id="myid" onmousedown="mouseDown()" onmouseup="mouseUp()">
This is demo heading.
</h3>
<p>Click above and then release.</p>
<script>
function mouseDown() {
document.getElementById("myid").style.color = "yellow";
}
function mouseUp() {
document.getElementById("myid").style.color = "blue";
}
</script>
</body>
</html>