There is an array of 1,3,5 and there is a select where each option has value = 'number'.

It is necessary to compare the array with option value = 'number'

If value has matches with numbers from the array, then add the selected attribute

$(document).ready(function(){ var arr = [1,3,5]; $('.click').click(function() { //???????????????? }); }); 
 select{ height: 300px; width: 100px; } .click { cursor: pointer; font-size: 20px; color: red; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div class='click'>click</div> <select multiple> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> </select> 

    1 answer 1

     $("select").val(arr); 

    (minimal'naja dlina tela 30 simvolov)

    • As everything is simple, I did not think of this option. Thank. jsfiddle.net/j7pm1b6y/1 - Sincopa
    • @Sincopa To health. Successes in programming! - Igor