SO - 4590979
by Arun P Johny
HTML
<ul>This is a sample set
<li>1</li>
<li>3</li>
<li>5</li>
<li>7</li>
<li>9</li>
</ul>
<div id="color"></div>
CSS
body
{
color: #008000;
}
JavaScript
setInterval(findYellow, 1000);
function findYellow()
{
$("ul").each(function(){
var $this = $(this);
$("#color").text(rgb2hex($this.css("color")));
if(rgb2hex($this.css("color")) != "#008000"){
$this.css("color", "#008000");
$this.text("abcd blue");
} else {
$this.css("color", "blue");
$this.text("abcd green");
}
});
}
var hexDigits = new Array
("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
//Function to convert hex format to a rgb color
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
function hex(x) {
return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}