jQuery css Method


jQuery css Method : is used to add the css styles to the selected elements.


Syntax 1

$(selector).css(propertyName);

propertyName(String): Css Style to be added.

jQuery css() Method Example 1

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#cssExample" ).on( "click", function(event) {             
                $("#cssClass").css('background','yellow');               
              });
               
          });
</script>

Try it »

Syntax 2 for jQuery css Method

$(selector).css(propertyNames);

propertyNames (Array): List of styles in form of array.
Example : {‘background’:’yellow’,’font-size’:’24px’,’border’:’2px solid red’}

jQuery css() Method Example 2

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#cssExample" ).on( "click", function(event) {             
                $("#cssClass").css({'background':'yellow','font-size':'24px','border':'2px solid red'});               
              });
               
          });
</script>

Try it »


User Ans/Comments

📖 Read More


Advertisements