Endless Tutorial - jQuery - css( properties ) method function

The css(properties) method sets a key/value object as a style property for all matched elements.

css( properties ) - Syntax

selector.css( properties )

The above syntax can be written as follows −

selector.css( {
   
   key1:val1, key2:val2....keyN:valN})

Here is the description of all parameters used by this method −

  • key:value - A key/value pair to set as a style attribute.

css( properties ) - example

Following is a simple example that simply illustrates the usage of this method −

<html>
   <head>
      <title>The jQuery Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
   
   
			
            $("div").click(function () {
   
   
               var color=$(this).css("background-color");
               $("#result").html("That div is <span>" + color + "</span>.");
               $("#result").css({
   
   color: yellow, font-weight : bold, 
                  background-color: gray});
            });
				
         });
      </script>
		
      <style>
         div {
   
    width:60px; height:60px; margin:5px; float:left; }
      </style>
   </head>
	
   <body>
      <p>Click on any square:</p>
      <span id="result"> </span>
		
      <div style="background-color:blue;"></div>
      <div style="background-color:rgb(15,99,30);"></div>
      <div style="background-color:#123456;"></div>
      <div style="background-color:#f11;"></div>
   </body>
</html>

This will produce the following output -

The css(properties) method function in jQuery - Wuya Tutorial Network Wuya Tutorial Network provides the css(properties) method to set the key/value object as the style attribute of all matching elements. css( properties ) -... https://www.learnfk.com/jquery/css-properties.html

Guess you like

Origin blog.csdn.net/w116858389/article/details/132020254