Check multiple checkboxes using jquery -


i have array

var values = ['1','3','4','5']; 

i have list of checkboxes

<div id='list'>     <input type='checkbox' value='1' />     <input type='checkbox' value='2' />     <input type='checkbox' value='3' />     <input type='checkbox' value='4' />     <input type='checkbox' value='5' />     <input type='checkbox' value='6' />     <input type='checkbox' value='7' />     <input type='checkbox' value='8' />     <input type='checkbox' value='9' />     <input type='checkbox' value='10' /> </div> 

now want select checkboxes values lies within array values. have done

for(var = 0; < values.length; i++)     $("#list [value=" + values[i] + "]").attr("checked", "checked"); 

it working fine can without loop.

thank in advance helpers.

try

$("#list").find('[value=' + values.join('], [value=') + ']').prop("checked", true); 

demo: fiddle


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -