lbennet lbennet - 5 months ago 30
jQuery Question

jquery autocomplete hides itself on window blur, disable this

jquery's autocomplete is hiding itself on window blur, how to prevent this?

Can't find the answer on the Internet.

Sounds simple but with the following code to determine window focus and blur I get display none for all autocomplete that were opened right before going into blur, seems window blur is the trigger for autocomplete to hide:

$(function() {
$(window).focus(function() {


$(window).blur(function() {


I wanted to set variables for all autocomplete that had a display other than none and then on focus display these, but on blur I get display none for all ".ui-autocomplete"


Try changing the autocomplete's blur event handler like this:

        source: ['cat','rabbit','donkey']
    }).off('blur').on('blur', function() {
        if(document.hasFocus()) {

Using the hasFocus() function you can check the focus of the current window and determine wether to close the options or not

jsFiddle here