Css ()

Source: Internet
Author: User

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>

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.