Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background color in jquery

Tags:

jquery

css

People also ask

How can get background color value in jQuery?

click(function() { var color = $( this ). css( "background-color" ); $( "p" ). html( "That div is " + color + "." ); });

How can set background color of button in jQuery?

To change the background color using jQuery, use the jQuery css() property. We will change background color on mouse hover with the jQuery on() and css() method.

What is the jQuery code to set the background color of all elements to red?

JavaScript Code:click(function(){ $("p"). add( "span" ). add("textarea"). css( "background", "red" ); });

Which jQuery code to set the background color of all SPAN elements to blue?

jQuery code to set the background color of all span elements to blue? A. $("span"). style("background-color","blue");


$(this).css('background-color', 'red');

You actually got it. Just forgot some quotes.

$(this).css({backgroundColor: 'red'});

or

$(this).css('background-color', 'red');

You don't need to pass over a map/object to set only one property. You can just put pass it as string. Note that if passing an object you cannot use a -. All CSS properties which have such a character are mapped with capital letters.

Reference: .css()


How about this:

$(this).css('background-color', '#FFFFFF');

Related post: Add background color and border to table row on hover using jquery


Try this for multiple CSS styles:

$(this).css({
    "background-color": 'red',
    "color" : "white"
});