Uncaught Error: Syntax error, unrecognized expression: hover

落爺英雄遲暮 提交于 2019-12-11 02:04:27

问题


Here is the JSFidle to the problem: http://jsfiddle.net/LRTh3/36/

$('div.boxes').mousedown(function (event) {

    // Error on this line
    var inner_box = $(".box").is(":hover");

    if ( inner_box == true ) {

        alert("blue,gree,pink was clicked");
    }

    else alert("You mousedowned on the red box");

});​

console: Uncaught Error: Syntax error, unrecognized expression: hover 

Works if only one ".box" layer is presented. Is this a bug? How would I fix this?


回答1:


$('div.boxes').mousedown(function (event) {

// Error on this line
var $target = $(event.target);    
if (  $target.is(".box")) {

    alert("blue,gree,pink was clicked");
}

else alert("You mousedowned on the red box");


});​

I lifted it from jQuery API doc



来源:https://stackoverflow.com/questions/10704183/uncaught-error-syntax-error-unrecognized-expression-hover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!