jquery css method

jquery css() method

this method is used to get the value of a style property for the first element in the set of matched elements or set one or more css properties for every matched element.


jquery - return css property

the jquery .css() method get the value of style properties for the first element in the set of matched elements.

the jquery css method syntax :-

        $(selector ).css ( property ) ;

property :- specifies the css property name like 'font-size' ,'color'.

the jquery css method example


jquery - set css property

the jquery .css (propertyname, value) method set one or more style properties for the selected elements.

the jquery css method syntax :-

        $(selector ).css ( propertyname,   value) ;

property :- specifies the css property name like 'font-size' , 'color'.

value     :- specifies the value of the properties like '12px' , 'black'.

jquery set css property example

</script>
       
                   <script>
                   
                   $(document).ready(function(){
                   
                   $("button").click(function(){
                   
                   $("p:first").css("color","blue");
                   
                   $("p:last").css("color","red");
                   
                      }); });
                                        
        </script>

how set multiple css properties.

to set multiple css properties, use the following syntax:-

 $( selector ).css ( { 'propertyname':'value' , 'propertyname':'value', ...} );

jquery set multiple css property example

          $(document).ready(function(){
            
                   $("button").click(function(){
                   
                   $("p:first").css({"color":"blue","border":"10px solid gold"});
                   
                   $("p:last").css({"color":"gold","border":"10px solid black"});
                   
                   });
 });