Search code examples
javascriptjqueryfocusblur

How unfocus on jQuery for is(':focus')


Sorry for my poor English. I'm using jQuery plugin slick. It contain some code

_isSlideOnFocus =_.$slider.find('*').is(':focus');
...
if(_isSlideOnFocus) {
    //some code that i don't want to execute
}

Plugin gives ability to execute callback right before upper code will execute. So i can unfocus elements, but i don't know how.

In browser console right before upper code i try

_.$slider.find('*').blur();
_.$slider.find('*').each(function() {$(this).blur()});
_.$slider.find('*').trigger('blur');

but it don't work's.

i try in console

_.$slider.find(':focus'); //empty jQuery object

_.$slider.find('*').each(function() {
    console.log($(this).is(':focus')); //false for all elements
});

_.$slider.find('*').is(':focus') //but this one returns true

Even if I try

_.$slider.find('*').each(function() {
        if($(this).is(':focus')) {
            $(this).blur();
            console.log($(this).is(':focus'));
        }
 });

console logs true, so as I can see blur is not working for is(':blur') How can i blur all elements in $slider? Thank's for help

Here the fiddle. My code in the end of js block. Subject plugin code is in the Slick.prototype.activateADA function in the end of plugin.


Solution

  • I have found the solution. I was using the old jQuery version 1.7. After updating jQuery to 1.9 blur works.