Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does .fireEvent() not trigger in IE9?

Rather frustrating time here with IE9. This code works in IE7/8, but not 9.

document.getElementById('id').fireEvent("OnChange");

Any insight as to why?

like image 802
tyler Avatar asked Mar 15 '12 05:03

tyler


People also ask

What is fireEvent?

Fire event means a response by the Des Moines Fire Department to extinguish a fire within a building, dwelling or other structure that commences with the dispatching of fire department resources and concludes with the fire officer in charge terminating the incident.

What is Javascript fireEvent?

Browser support: Initializes an event object and dispatches it to the current element. To create an event object, use the createEventObject method in Internet Explorer. The created event can be passed as a second parameter of the fireEvent method.


1 Answers

In IE versions >= 9 and all other browsers you should use the dispatchEvent method:

var event = document.createEvent("HTMLEvents");
event.initEvent("change",true,false);

document.getElementById("id").dispatchEvent(event);

Check out http://jsfiddle.net/QKsvv/

like image 189
Strelok Avatar answered Oct 06 '22 18:10

Strelok