.is(“:hover”) is broken as of jQuery 1.9 How to fix

后端 未结 3 1642
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 15:08

When doing $(...your selector here...).is(\":hover\"), jQuery prior to 1.9.1 gave correct answer, while jQuery 1.9.1 tells you this:

Erro

3条回答
  •  感情败类
    2020-12-05 15:56

    You could try to use .filter()

    I think, my solution will help you:

    //
    // jQuery 3 pseudo ':hover' doesn't support
    //
    
    // Working on jQuery 1.7.1
    $("*").on('click', $.proxy(function() {
        if ( this.$('.tooltip:hover').length > 0 ) { // jQuery 3.2.1 -> Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: hover
          console.log('Hovered!');
        } else { 
          console.log('Where is my element!?'); 
        }
    }, this));
    
    
    // Updated solution for jQuery 1.7.1 - 3.2.1
    $("*").on('click', $.proxy(function() {
        var isHovered = $('.tooltip').filter(function() {
            return $(this).is(":hover");
        });
    
        if ( isHovered.length > 0 ) {
          console.log('Hovered!');
        } else { 
          console.log('Where is my element!?'); 
        }
    }, this));
    

    also, you can see my GitHub gist:https://gist.github.com/antydemant/74b00e27790e65f4555a29b73eea7bb2

提交回复
热议问题