Check Checkboxes Based On Values In An Array
Checkbox check with Array or values Html Code:
$('#'+f.join(', #')).prop('checked', true);
Solution 2:
With the forEach method of Array this is very simple even without JQuery.
f.forEach(function(i){
document.getElementById(i).checked = true;
});
You can read more about for each on the Mozilla Developer Network
Solution 3:
One simple way is iterate over the array and use prop
method along with id selector.
for(var i=0;i<f.length;i++) {
$('#' + f[i]).prop('checked', true)
}
Post a Comment for "Check Checkboxes Based On Values In An Array"