简体   繁体   English

使用jQuery更改元素的颜色

[英]Change color of elements using jQuery

This should be easy but I'm not getting it for some reason. 这应该很容易,但由于某些原因我没有得到它。 How would I set the CSS color style (eg color:green) of all the elements who are of class 'foobar' using jQuery? 如何使用jQuery设置所有“foobar”类的元素的CSS颜色样式(例如颜色:绿色)?

You want the color to go green just on mouseover? 您希望鼠标悬停时颜色变为绿色吗? Can you be more specific? 你可以说得更详细点吗?

$('.foobar').mouseover( function() {
  $(this).css( { color: 'green' } );
} );

This can be done with plain CSS: 这可以通过纯CSS完成:

.foobar {
    background-color:red;
}

.foobar:hover {
    background-color:green;
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM