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

后端 未结 3 1645
伪装坚强ぢ
伪装坚强ぢ 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:41

    However the workaround above is unsuitable when you are comparing elements using jQuery.fn.is() with a composed selector which is not known beforehand, and that could match several elements in the parent container.

    eg, the same exception is thrown when selectorText in style_get() below is equal to: ".mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar, .mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar"

    ..because hover is not defined in Sizzle.selectors.pseudos or Sizzle.selectors.setFilters (jquery-2.1.4, line 1764)..

    function style_get(elem) {
    
      var sheets=document.styleSheets;
      var css_properties={};
      elem=$(elem);
    
      for (var s in sheets) {
        var rules=sheets[s].rules || sheets[s].cssRules;
    
        for (var r in rules) {
          if (elem.is(rules[r].selectorText)) {
    
            css_properties=$.extend(
              css_properties,
              css.parse(rules[r].style),
              css.parse(elem.attr('style'))
            );
    
          }
        }
    
      }
    
      return css_properties;
    
    }
    

提交回复
热议问题