How to apply multiple CSS properties using a single jQuery method?
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?
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.