As Pete suggested, use data attribute which is better and easy way: http://jsfiddle.net/aamir/tq9W8/5/
$('#listbox option:eq(0)').css('color', 'red').data('color', 'red');
$('#listbox').change(function () {
if ($(this).find("option:selected").data('color') == 'red') {
alert('color is red');
} else {
alert('other options');
}
});
or you can try this: http://jsfiddle.net/aamir/tq9W8/4/
$('#listbox option:eq(0)').css('color', 'red');
function checkColorByName(ele, colorName) {
var tempDiv = $('<div>').css("color", colorName).hide().appendTo('body');
console.log(tempDiv.css('color'));
var bol = tempDiv.css('color') == ele.css('color');
tempDiv.remove();
return bol;
}
$('#listbox').change(function () {
if (checkColorByName($(this).find("option:selected"), 'red')) {
alert('color is red');
} else {
alert('other options');
}
});
Other wise according to this, you need to use a plugin.