2011-04-12 80 views
0

即时尝试为图像创建边框时,我将鼠标悬停但它不添加它:S但我已尝试console.log,它显示文字我已写入,但它dosent添加类到它:小号jquery addclass问题

这是我的代码

<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'); 
}); 
+0

你为什么要使用jQuery和CSS不? '.thumb:hover {border:1px solid#000}'? – Phil 2011-04-12 21:32:10

+0

你有一个jsfiddler.net的例子,你在做什么? – LeRoy 2011-04-12 21:33:39

回答

0

为什么你需要的JavaScript的呢?

标记:

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

CSS:

#foo {width:50px; height:50px; border: 1px solid blue} 
#foo:hover {border-color: red} 

工作示例:http://jsfiddle.net/JndDd/

+1

':悬停'不工作在IE浏览器,除非该元素是一个锚点 – Neal 2011-04-12 21:33:32

+0

@Neal对于IE 7及以下;这在我看来不是问题。 – Phil 2011-04-12 21:37:09

+0

好吧,我想到那:),但它仍然没有工作:我尝试#small-image.thumb:悬停{0} {0} {0} {0} border:5px solid blue; } – ole 2011-04-12 21:54:20

0

问题也许是你的基地覆盖CSS样式在test类?

如果你不在乎IE6,你可以做整个事情与CSS:

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

试图在你选择删除的空间:

$('#small-image .thumb') 

$('#small-image.thumb')