This should be easy but I'm not getting it for some reason. How would I set the CSS color style (e.g. color:green) of all the elements who are of class 'foobar' using jQuery?
+4
A:
You want the color to go green just on mouseover? Can you be more specific?
$('.foobar').mouseover( function() {
$(this).css( { color: 'green' } );
} );
thenduks
2009-12-30 03:39:36
This might not be what @JamesBrownIsDead wanted, the title says something about mouseover. This exact behavior can be achieved without the use of javascript, just CSS
Pablo Fernandez
2009-12-30 03:42:29
Could also be expressed as: $(".foobar").css("color", "green");
Chase Seibert
2009-12-30 03:42:53
@Pablo: True, fleshed it out. Need more info from the asker :)
thenduks
2009-12-30 03:43:59
@Chase: Of course, that's true. I've been annoyed one too many times by needing to add another css property and having to rewrite the parameters :)
thenduks
2009-12-30 03:44:44
Seems like you were right since this is the accepted answer. Gonna rephrase the question, and specially the title
Pablo Fernandez
2009-12-30 03:45:32
A:
This can be done with plain CSS:
.foobar {
background-color:red;
}
.foobar:hover {
background-color:green;
}
Chase Seibert
2009-12-30 03:45:24