Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use javascript to modify onmousedown of div at runtime

I want to write some JavaScript that will change the onmousedown of a div at runtime. So on load a mouse down on the div will do one thing and if a JavaScript function is called a mouse down on the div will do something else. Is this possible?

like image 585
mrjrdnthms Avatar asked Dec 14 '22 06:12

mrjrdnthms


1 Answers

You can just assign the onMouseDown property.

document.getElementById('myDiv').onmousedown = function() {
  alert('New mouse down handler.');
};

Keep in mind that javascript properties are case-sensitive. "onmousedown" is all lower-case.

like image 179
Prestaul Avatar answered Jun 06 '23 18:06

Prestaul