jqueryaddclass问题

jqueryaddclass问题,jquery,css,image,class,add,Jquery,Css,Image,Class,Add,当我将图像悬停时,我试图给它添加边框,但它没有添加:S,但我有try console.log,它显示了我写的文本,但没有添加类:S 这是我的密码 <style> .test { border: 1px solid #000; } </style> // add a class to the image that is focus on $('#small-image .thumb').hover(function() { $(this).addClass(

当我将图像悬停时,我试图给它添加边框,但它没有添加:S,但我有try console.log,它显示了我写的文本,但没有添加类:S

这是我的密码

<style>
.test {
    border: 1px solid #000;
}
</style>
// add a class to the image that is focus on
$('#small-image .thumb').hover(function() {
    $(this).addClass('test');
        console.log('hover');
}, function() {
    $(this).removeClass('test');
        console.log('out');
});

.测试{
边框:1px实心#000;
}
//向聚焦的图像添加一个类
$('#small image.thumb')。悬停(函数(){
$(this.addClass('test');
console.log('hover');
},函数(){
$(this.removeClass('test');
console.log('out');
});

为什么需要javascript来实现此功能

标记:

<div id="foo"></div>

工作示例:

问题可能是您的基本CSS覆盖了
测试
类中的样式

如果您不关心IE6,您可以使用CSS完成所有工作:

#small-image.thumb:hover {
    border: 5px solid blue;
}

您的代码似乎运行正常:


无论问题是什么,都与您发布的内容无关。

尝试删除选择器中的空格:

$('#small-image .thumb')


为什么使用jQuery而不是css
.thumb:hover{border:1px solid#000}
?您是否有一个jsfiddler.net示例来说明您正在做什么?@Neal用于IE 7及以下版本;在我看来这不是问题。好吧,我没有想到:),但它仍然不起作用:我尝试#小图像。拇指:悬停{border:5px solid blue;}@ole,尝试在jsfiddle.net上发布代码,然后在这里发布新问题的链接
$('#small-image .thumb')
$('#small-image.thumb')