Can you use javascript to change the onmousedown div at runtime

I want to write some JavaScript that will change the onmousedown div at runtime. Thus, when loading the mouse on the div will do one thing, and if the JavaScript function is called the mouse down, then the div will do something else. Is it possible?

+4
source share
1 answer

You can simply set 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 lowercase.

+13
source

Source: https://habr.com/ru/post/1277481/


All Articles