Q:

apply multiple selected true to option jquery

<select id="testd" name="testd[]" multiple="" style="min-height: 100px;">
    <option value="16">test1</option>
    <option value="21">test2</option>
    <option value="27">test3</option>
    <option value="24">test4</option>
</select>

how to apply seleted true to multiple option , 
example 16,24 , want to apply seleted true to option 
i tried 
var optionsToSelect = ['16,24'];
              var select = document.getElementById( 'testd' );

              for ( var i = 0, l = select.options.length, o; i < l; i++ )
              {
                o = select.options[i];
                console.log(o);
                if ( optionsToSelect.indexOf( o.value ) != -1 )
                {
                  o.selected = true;
                }
              }

not working perfectly , it will selects all the four options

A:

Change
var optionsToSelect = ['16,24'];

to
var optionsToSelect = ['16','24'];

This is how to define an array of strings. Else your code works fine.
Working Demo

