The CSS code is as follows:
1 2 |
a, a:link, a:visited { color : #4188FB ; } a:active, a:focus, a:hover { color : #FFCC00 ; } |
The JS code is as follows:
1 2 |
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 function below to turn RGB into "#xxxx" (HEX) format.
1 2 3 4 5 6 7 8 9 Ten One A - |
var rgbString = "rgb(0, 70, 255)" ; // get this in whatever way. var parts = rgbString .match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/) ; // parts now should be ["rgb(0, 70, 255", "0", "70", "255"] delete (parts[0]); for ( var i = 1; i <= 3; ++i) { parts[i] = parseInt(parts[i]).toString(16); if (parts[i].length == 1) parts[i] = ‘0‘ + parts[i]; } var hexString = parts.join( ‘‘ ); // "0070ff" |
or use this function.
1 2 3 4 5 6 7 |
function rgb2hex(rgb) { rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); function hex(x) { return ( "0" + parseInt(x).toString(16)).slice(-2); } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } |
Transferred from: http://www.ghugo.com/jquery-css-color-value-returns-rgb/
jquery Gets the CSS color value returned RGB