2

I found this code snippet here, works perfectly but not for IE.

var testTwo = document.getElementById('testOne')

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);
  }
}

function testInt(){
eventFire(testTwo, "click");
};
setInterval(testInt, 3000);

can anyone tell me how to get it work in IE?

thank you

xhallix
  • 2,919
  • 5
  • 37
  • 55

2 Answers2

3

Try

function eventFire(el, etype) {
    var event;
    if (document.createEvent) {
        event = document.createEvent("HTMLEvents");
        event.initEvent(etype, true, true);
    } else {
        event = document.createEventObject();
        event.eventType = etype;
    }

    event.eventName = etype;

    if (el.dispatchEvent) {
        el.dispatchEvent(event);
    } else {
        el.fireEvent("on" + etype, event);
    }
}}

Demo: Fiddle

Logic taken from this question

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

You should be able to use fireEvent to trigger the event. Here is the MSDN article about it.

Andy Meyers
  • 1,561
  • 1
  • 15
  • 21