Jquery obtains the css Value

Source: Internet
Author: User

Provides two different methods and codes for jquery to obtain css values, now jquery is used to set the css width, whether it is css or others. $ (\ "# JS_top_ment \" ).css (\ "width \", \ "60% \") is very convenient.

Provides two different methods and codes for jquery to obtain the css tutorial value, now jquery is used, whether it is css or other operations, it is very convenient $ ("# webpage special effect _ top_ment" ).css ("width", "60%") settings, css width.

The css format of jquery is ("attribute", "parameter ")


If you want to get the percentage of width, enter the following code.

Math. round ($ ("# js_top_ment"). width ()/$ (document). width () * 100)


Method 2

Var cssrules+document.stylesheets%0%.css rules | document. stylesheets [0]. rules;
Alert (cssrules [0]. style. color)


Html code

<Link href = "my.css" type = "text/css" rel = "stylesheet"/>
<Div class = "test">
<Span> test </span>
</Div>

Css code

. Test span {color: red ;}

Related Article

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.