Search code examples
htmlcsshtml-selectjquery-ui-multiselect

because of 'multiple' attribute background color gets changed to grey


.selected_aq{
background:#47D6EB !important;
color : #fff;
}

<select id="abc" multiple="multiple">
<option value="Customer 1" class="selected_aq">Customer 1</option>
<option value="Customer 1" class="selected_aq">Customer 1</option>
</select >

 for (x=0;x<list.options.length;x++){
         if (list.options[x].selected){
             $(list.options[x]).addClass('selected_aq');
          }

Because of 'multiple' attribute background color gets changed to grey but only for last selected 'option'.


Solution

  • You can use CSS only

    select[multiple]:focus option:checked {
      background: #47D6EB linear-gradient(0deg, #47D6EB 0%, #47D6EB 100%);
      color : #fff;
    }
    <select id="abc" multiple="multiple">
      <option value="Customer 1" >Customer 1</option>
      <option value="Customer 2" >Customer 2</option>
      <option value="Customer 3" >Customer 3</option>
      <option value="Customer 4" >Customer 4</option>
      <option value="Customer 5" >Customer 5</option>
      <option value="Customer 6" >Customer 6</option>
    </select >

    Try to select multiple options by holding Ctrl button.