-->

jquery focusout event missing relatedTarget inform

2019-05-11 06:32发布

问题:

i have a text input that is bound to focusin/focusout events.

$(element)
    .focusin(function(e) {})
    .focusout(function(e) {
        var to = e.relatedTarget || e.toElement;
        // undefined in chrome, fine in IE
    });

on focusout, i'm interested in the relatedTarget information, i.e., the DOM element receiving focus as the text input loses focus, however this property is undefined for the event.

on the other hand, toElement, which i believe is the internet explorer equivalient of relatedTarget, is available. in other words, my focusout handler works fine in IE, but not in other browsers.

is there a workaround for the above limitation?

回答1:

From the MDC docs:

Only MouseEvents have this property

focusout is not a mouse event, so relatedTarget is not set. IE is not following standards here (what's new?).