When I trigger a focus
event with dispatchEvent
on an input box, its onfocus
is called, but on the UI the input box is not focused.
Is there any reason for this behavior?
var test = document.getElementById(test);
test.onfocus = function(event) {
console.log('focused');
}
var e = document.createEvent('Event');
e.initEvent(focus, true, true);
test.dispatchEvent(e);
On the other hand this works as expected.
var test = document.getElementById(test);
test.focus();
The reason i'm investigating this is that I use ZeptoJS to trigger events and it uses dispatchEvent
.