Reputation: 1393
I am trying to use the code below to hide a div using a mousedown event, but it's not working.
I have tried a lot of changes to this code without any luck.
This is my code below:
function simulateMouseDown(theelement){
var eventName = 'mousedown';
if(theelement.dispatchEvent){
var event = document.createEvent("MouseClick");
event.initMouseEvent(eventName, true, true, window);
alert(theelement.dispatchEvent(event));
}else if(theelement.fireEvent){ // IE7 and below
theelement.fireEvent('on'+eventName);
alert(theelement.dispatchEvent(event));
}
};
Any ideas as to the proper way to do this?
Upvotes: 1
Views: 904
Reputation: 5620
document.getElementById('myButton').addEventListener('mousedown', function(evt){
document.getElementById('elementToHide').style.display='none';
}, true);
Upvotes: 0