Question about how JQuery gets the background-color value in a style

Source: Internet
Author: User

Today, when JQuery is used to obtain the value of background-color in the style, the obtained color value is displayed in different formats than Chrome and Firefox in IE. in IE, the color value is displayed in HEX format [# ffff00 ], chrome and Firefox display [rgb (255,255, 0)] in GRB format, and what I need is a hexadecimal color value, which is used for storage to the database, find the following code on the Internet to solve the problem:
Copy codeThe Code is as follows:
$. Fn. getHexBackgroundColor = function (){
Var rgb = background (this).css ('background-color ');
If (! $. Browser. msie ){
Rgb = rgb. match (/^ rgb \ (\ d +), \ s * (\ d +), \ s * (\ d +) \) $ /);
Function hex (x ){
Return ("0" + parseInt (x). toString (16). slice (-2 );
}
Rgb = "#" + hex (rgb [1]) + hex (rgb [2]) + hex (rgb [3]);
}
Return rgb;
}

In this way, all are displayed in HEX format and have been verified.

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.