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

Asked 3 years ago 173 views 1 answer Modified 7 hours 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: ```javascript $('.myclass').css('background-color': 'red', 'color': 'white'); ``` What's the correct syntax for applying multiple CSS properties at once with jQuery?
shama-naaz
50 reputation

1 Answer

0
To use multiple CSS properties and values using a single jQuery method use following code: ```javascript $('.myclass').css({'background-color': 'red','color':'white'}); ``` Note the use of curly braces `{}` to create an object with multiple property-value pairs. Each property-value pair is separated by a comma.
imran-nadwi
answered 3 years ago
You can use Markdown to format your answer.
Last edited: 3 years ago
Preview: