Pregunta

When you .trigger("focus") in IE, jQuery won't "see" the async focus event which will occur later, so it fires one of its own to ensure that a focus event always occurs as described above. This causes two calls to the event handler. To avoid this double-call--but risk that the event handler is not called at all--use the DOM focus method directly, e.g., $("selector").get(0).focus().

This is what jquery migrate site says. Although I was not clear if every trigger.focus needs to be replaced with new implementation? IF so what would be the new code be for a simple button. trigger focus?

 $('#btnMove').trigger('focus');
¿Fue útil?

Solución

Read Order of triggered "focus" events

Get Native DOM Element and call focus event on it.

$('#btnMove').get(0).focus();

Or

$('#btnMove')[0].focus();

Or Use Pure JavaScript

document.getElementById('btnMove').focus();

Otros consejos

You can use on method

$('#btnMove').on('focus', handler);

Also, you can read http://api.jquery.com/focus/ and a note you would find:

Attempting to set focus to a hidden element causes an error in Internet Explorer. Take care to only use .focus() on elements that are visible. To run an element's focus event handlers without setting focus to the element, use .triggerHandler( "focus" ) instead of .focus().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top