Home >Web Front-end >JS Tutorial >jQuery's css() method usage example_jquery
The example in this article describes the usage of jQuery’s css() method. Share it with everyone for your reference. The specific analysis is as follows:
This method returns or sets one or more style attributes of the matched element.
Grammar structure:
Grammar 1:
Get the attribute value of the specified style attribute.
Take the style attribute name as parameter. For example:
The above code can obtain the font color value of the div.
Code example:
Grammar 2:
Set a style attribute value for all matching elements. For example:
The above code can set the font color of all divs to red. Everyone should pay attention to the writing format. The attribute name and attribute value should be wrapped in banks and separated by commas. If the attribute value is a number, you can remove the quotation marks, for example:
Example code:
Grammar 3:
Use the "attribute name/value" object to set the style attribute for all matching elements. For example:
The above code can set the font color of all div elements to red. You can also set multiple sets of attributes for matching elements at one time using the "attribute name/value" object method. For example:
In the above code, clicking the button can modify the text color and font size in the div.
I hope this article will be helpful to everyone’s jQuery programming.