jquery Gets the CSS color value to return the RGB method _jquery

Source: Internet
Author: User

The example in this article tells jquery how to get the color value of a CSS to return RGB. Share to everyone for your reference, specific as follows:

The CSS code is as follows:

A, a:link, a:visited {color: #4188FB;}
A:active, A:focus, a:hover {color: #FFCC00;}

The JS code is as follows:

var Link_col = $ ("A:link"). CSS ("color");
alert (Link_col); Returns RGB (65, 136, 251)

Jquey seems to set the color, using the RGB format.

Use the following function to convert RGB to the #xxxx (HEX) format.

var rgbstring = "RGB (0, 70, 255)"; Get this in whatever way.
var parts = Rgbstring.match (/^rgb\ (\d+), \s* (\d+), \s* (\d+) \) $/);
Parts now should is ["RGB (0, 255", "0", "", "255"]
Delete (parts[0));
for (var i = 1; I <= 3; ++i) {
Parts[i] = parseint (parts[i)). toString ();
if (parts[i].length = = 1) parts[i] = ' 0 ' + parts[i];
}
var hexstring = Parts.join ('); "0070FF"

or use this function.

function Rgb2hex (RGB) {
RGB = Rgb.match (/^rgb\ (\d+), \s* (\d+), \s* (\d+) \) $/);
function Hex (x) {return
("0" + parseint (x). toString). Slice ( -2);
}
Return "#" + Hex (rgb[1]) + hex (rgb[2]) + hex (rgb[3));


I hope this article will help you with the jquery program design.

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.