/ Published in: JavaScript
bgcolor = $('div').css('background-color');
if(bgcolor != 'transparent') { bgcolor = rgb2hex(bgcolor); };
Expand |
Embed | Plain Text
//Function to convert hex format to a rgb color function rgb2hex(rgb) { var hexDigits = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]; rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); function hex(x) { return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); }
You need to login to post a comment.
