How to apply multiple CSS properties using a single jQuery method?

Asked 3 years ago 125 views 1 answer Modified 1 days ago
11

I want to apply multiple CSS properties and values to an element using a single jQuery method call.

I tried this syntax but it doesn't work:

$('.myclass').css('background-color': 'red', 'color': 'white');

What's the correct syntax for applying multiple CSS properties at once with jQuery?

Imran Nadwi
50 reputation

1 Answer

0

To use multiple CSS properties and values using a single JQuery method use following code:

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

CodingerWeb
answered 3 years ago
You can use Markdown to format your answer.
Last edited: 3 years ago
Preview: