views:

62

answers:

2

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
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
Could also be expressed as: $(".foobar").css("color", "green");
Chase Seibert
@Pablo: True, fleshed it out. Need more info from the asker :)
thenduks
@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
Seems like you were right since this is the accepted answer. Gonna rephrase the question, and specially the title
Pablo Fernandez
A: 

This can be done with plain CSS:

.foobar {
    background-color:red;
}

.foobar:hover {
    background-color:green;
} 
Chase Seibert
Unfortunately this wont work in IE for non-anchor elements.
thenduks
Also he never said he wanted the color going back to what it was before :)
thenduks