CSS () can pass the attribute name of a string for this method. For example, CSS ('backgroundcolor '). for attribute names composed of multiple words, JQ can be understood as CSS notation (for example, CSS ('background-color ')), it can also be understood as DOM Representation (for example, CSS ('backgroundcolor') in the case of hump ')).
Three methods of CSS:
1. CSS (Key, value) sets a style for the matching element.
Key (string): name of the style attribute to be set
Value (object): the value of the style attribute to be set
Example:
Example: change the color style attribute values of all paragraphs to red.
$ ("P" ).css ("color", "red ");
HTML code: <p> Test Paragraph. </p>
Result: <p style = "color: red;"> Test Paragraph. </p>
2. css (name) accesses the style attribute of the First Matching Element. Obtain the attribute value of the First Matching Element style.
Name (string): name of the attribute to be accessed
Example:
Example: Get the value of the color Style attribute of the First Section
$ ("P" ).css ("color ");
HTML code: <p style = "color: red;"> Test Paragraph. </p>
Result: red
3. css (properties) sets many styles on all matching elements.
Properties (MAP): name/value pair object to be set as a style Property
Example:
Example: Set the color and background style attributes for all P elements.
$ ("P" ).css ({color: "red", Background: "blue "});
HTML code: <p> test paragraph. </P>
Result: <P style = "color: red; Background: Blue;"> test paragraph. </P>