1

Below code doesn't seem to change the background color of dropdownlist. Please advice.

 var TextHighlightCss = {
        'background': '#FFFFAA',
        'border': '1px solid #FFAD33'
    };

 $('#ddlCarriers option:selected').css('TextHighlightCss');

Thanks in advance

BB

BumbleBee
  • 10,429
  • 20
  • 78
  • 123

3 Answers3

5
$('#ddlCarriers option:selected').css(TextHighlightCss);

You're passing a string, not your variable.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
0

Remove the apostrophes from the .css() part and it should work.

Also, you may like to see this:

http://www.456bereastreet.com/lab/form_controls/select/

It shows the style differences between all browsers for select menus, quite handy.

TheCarver
  • 19,391
  • 25
  • 99
  • 149
0

Please do it like this, if you can help it:

CSS:

.hightlight {
  background: #FFFFAA;
  border: 1px solid #FFAD33;
}

JS:

$('#ddlCarriers option:selected').addClass("hightlight");

Guy who needs to refactor it in the future:

(n/a)

karim79
  • 339,989
  • 67
  • 413
  • 406