How to set different colors for different options in a select with jQuery
I'm trying to generate a 'select' with a different color for each 'option' with jQuery.
I did that:
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
</head>
<body>
<select id="taxonomy" name="taxonomy"></select>
<script type="text/javascript">
$开发者_如何学运维(document).ready(function() {
$('#taxonomy').append($('<option></option>').val('-ANY-').html('-- ANY --'));
$('#taxonomy').append($('<option></option>').val('Critical').html('Critical'));
$('#taxonomy').append($('<option></option>').val('Warning').html('Warning'));
$('#taxonomy option[value="Critical"]').css('color', 'red');
$('#taxonomy option[value="Warning"]').css('color', 'orange');
});
</script>
</body>
</html>
Unfortunately, it's only working on Firefox. There is no color in Chrome or Safari...
Do you have better solution working on any browser ?
Thanks.
works fine for me !
using latest chrome on windows. I know there is/was a os x webkit bug for it thou.
精彩评论