---
title: "Why are use the .CSS() method in JQuery? and how to change the css property using .CSS() ."  
description: "Why are use the .CSS() method in JQuery? and how to change the css property using .CSS() ."  
author: "Ethan Karla"  
published: 2021-07-28  
canonical: https://answers.mindstick.com/qa/93804/why-are-use-the-css-method-in-jquery-and-how-to-change-the-css-property-using-css  
category: "web application"  
tags: ["web application development", "web development"]  
reading_time: 2 minutes  

---

# Why are use the .CSS() method in JQuery? and how to change the css property using .CSS() .

Why are use the .[CSS](https://www.mindstick.com/forum/514/background-gradient-ie7-css-problem)() [method in JQuery](https://www.mindstick.com/forum/156670/has-method-in-jquery)? and how to change the css [property](https://www.mindstick.com/articles/44059/couple-of-supportive-tips-when-taking-a-gander-at-property-for-sale) using .CSS() .

## Answers

### Answer by Ravi Vishwakarma

css [method](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) In web development we are change the property of the elements in html page using the CSS property. When we are development the dynamic website, then we need to change the style of element. So we can apply the css method for changing the style of html page and if we get the css property of selected element.

```
 Syntax
  .css(property-name);   return the set css property of selected ee
  .css({“property-name”:”value”})          set the css to selected elements
```

```
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>val demo</title>
    <style>
        select {
            width:150px;
            height:20px;
        }
    </style>
    <script src='https://code.jquery.com/jquery-1.10.2.js'></script>
</head>
<body>
    <p style='color:white;'></p>
    <select id='color'>
        <option>Select Color</option>
        <option>Red</option>
        <option>Blue</option>
        <option>Black</option>
        <option>Pink</option>
        <option>Yellow</option>
        <option>Cyan</option>
    </select>
    <script>
        function displayVals() {
            var colorName = $('#color').val();
            alert('CSS property : ' + $('body').css('background-color'));
            $('body').css({ 'background-color': colorName.toLowerCase() });
        }
        $('select').change(displayVals);
    </script>
</body>
</html>
```

![Why are use the .CSS() method in JQuery? and how to change the css property using .CSS() .](https://answers.mindstick.com/questionanswer/ca8750dd-5d9a-431c-8536-55a4f0306f66/images/91e864af-c02c-4db1-93ae-9e3df4983d06.png)\


---

Original Source: https://answers.mindstick.com/qa/93804/why-are-use-the-css-method-in-jquery-and-how-to-change-the-css-property-using-css

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
