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

Asked 3 years ago 140 views 1 answer Modified 6 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:

$('.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:

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

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