How to apply CSS properties using jQuery?

jQueryWeb DevelopmentFront End Technology

To apply CSS properties using jQuery, use the css() method. It’s easy to apply any CSS property using jQuery method css( PropertyName, PropertyValue ).

Here is the syntax for the method −

selector.css( PropertyName, PropertyValue );

Example

Here you can pass PropertyName as a JavaScript string and based on its value, PropertyValue could be string or integer.

Live Demo

<html>

   <head>
      <title>jQuery css() method</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {
            $("li").eq(4).css("color", "green");
         });
      </script>
   </head>
   
   <body>
   
      <div>
         <ol>
            <li>list item 1</li>
            <li>list item 2</li>
            <li>list item 3</li>
            <li>list item 4</li>
            <li>list item 5</li>
            <li>list item 6</li>
         </ol>
      </div>
       
   </body>
</html>
raja
Published on 17-Dec-2017 08:05:20
Advertisements