css – How to set background color in jquery

css – How to set background color in jquery

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

You actually got it. Just forgot some quotes.

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

or

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

You dont 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()

css – How to set background color in jquery

How about this:

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

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

Leave a Reply

Your email address will not be published.