In my html, I have an html element with a mouseover event handler. Can you please tell me if it is possible for me to invoke that event handler programmically in JavaScript?
It is possible. Here's a cross browser function to fire an event:
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
// => exmaples
// => eventFire(myDiv,'mouseover');
// => eventFire(myButton,'click');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With