ShellZero ShellZero - 1 year ago 435
Javascript Question

setTimeout in IE 11 is not working properly

I am using the setTimeout function to set the focus on a button element of a bootstrap modal. The following is the small piece of code which I wrote:

let element = this.el.nativeElement;
setTimeout(() => element.focus(), 200);

This works correctly on Firefox and Chrome. But on IE 11, I get the focus on the button for a blink of a second and it looses focus.

Do I have to do anything different in the case of IE 11 here? Am I doing something wrong?

Any help would be really appreciated.

Thank you.


Answer Source

IE11 doesn't support arrow functions. You will need to pass a function reference instead:

setTimeout(function (){ element.focus(); }, 200);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download