Closed
Description
Hi all,
I just noticed and odd change in the behavior of the focus method in jQuery 3.4.0 compared with 3.3.1, 2.**, and 1.. versions in a specific case when we try to change the focus to the child element in focusin event of its parent. Here is the code and here you can see a code dojo with the issue:
<span>Check the console</span>
<div id="toolbar" tabindex="0">
<a tabIndex="0" id="foo" >foo</a>
</div>
<script>
$(document).ready(function () {
var toolbar = $('#toolbar');
toolbar.on("focusin", function (ev) {
var element = $(this).find("a");
if (element.length) {
element[0].focus();
console.log(document.activeElement)
}
})
toolbar[0].focus();
//toolbar[0].focus(); this works
console.log('With 3.3.1 here we expect to see "foo":', document.activeElement.id);
});
</script>
If we use older version or the native focus() method the issue is not present.
Greetings.
Plamen