Search code examples
javascriptjqueryhtmlcssopera

jQuery Opera focus event not working


There is a search input and a complex drop-down div under it. The script shows the div when focus is on the input.

It works fine everywhere except in Opera. In Opera when I focus the input, nothing happens. But, if I click on another desktop application, like checking my mail, and then go back to the website, the drop-down on the website suddenly shows.

What is a way to fix this?

function checkSf() {
    if ($('#search-field').val() != "" || $('#search-field').is(":focus")){
        $('.search-dropdown').show();
    } 
}
$('#search-field').keyup(function(){
    checkSf()
});

$('#search-field').on('focus', function(){
    checkSf()
});

Solution

  • Actualy i found an answer. This bug is the same as in safari and chrome. To fix this i've added a zero timeout.

    Strangely it worked.

    function checkSf() {
        setTimeout(function(){
            if ($('#search-field').val() != "" || $('#search-field').is(":focus")){
                $('.search-dropdown').show();
            } 
        },0);
    
    }