The property name to use is "css", not "style". Also the value should be an object whose properties are the CSS properties to set.
$('#newuserSelect')
.append($('<option>', {
value: "0",
title: "hello",
css: { color: "red" }
})
.text("my text"));
You can, incidentally set the text with that initialization object too:
$('#newuserSelect')
.append($('<option>', {
value: "0",
title: "hello",
css: { color: "red" },
text: "my text"
})
);
Now, this does work, but it's important to note that when you're looking at the page with the <select>
element not "open", you're not looking at the <option>
elements. If you want the selected text to be red, then you need to also style the <select>
element itself. When there's only one <option>
, the <select>
cannot be "opened" so you never see the style of the <option>
.
I can't recall exactly but it may be the case that IE, or old versions of it anyway, won't pay attention to styles on <option>
elements. IE <select>
was implemented in a really weird way in old versions.