I would like to prevent the default event from a focusOut (or blur) event and keep the focus set to the specific input field.
This is what I have already tried:
using
event.preventDefault()at the beginning and at the end of the function (for test purposes, not for style)return false;to prevent propagationsetting the focus back to the element directly in the element (but I found that the focus still switches because the focus switch is executed after the
.on()function executes. I know I could usesetTimeout, but I’d like to avoid it and figure out the heart of the issue.)using
blurinstead offocusOut
My code is this:
_triggerEventHide: function(inst, eventType) {
inst.$target.on(eventType, function(event) {
event.preventDefault();
if (!$.suggestBox.$divCont.hasClass($.suggestBox.mouseOverClassName)) {
$.suggestBox.$divCont.css({display: 'none'}); //reposition Suggestbox
} else {
inst.target.focus();
}
event.preventDefault();
return false;
});
}
Note that $target represents the jQuery-wrapped element and target represents the native DOM element.
I’ve done some research and have found already a few articles relating to my question, but none of them answer this exact question.
preventDefault does not work on focus event – Here, the answer given is an alternate route to using any kind of event manipulation.