How to define multiple CSS attributes in jQuery?



To define multiple CSS attributes in jQuery, use the css selector or the addClass() method. Let’s see how to do it using css selector.

Pair up strings representing property names with the corresponding values.

Example

You can try to run the following code to learn how to define multiple CSS attributes in jQuery:

Live Demo

<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#demo").css({
    "background-color": "#F1F1F1",
    "font-style"     : "italic"
});
   
});
</script>

</head>
<body>
<h1 id="demo">Countries</h1>

</body>
</html>

Advertisements