Reputation: 293
I have an javascript array filled with values of checkboxes in a html file. How can i find the specific element and change checksign from jquery.
jQuery.each(substr, function() {
var n = this;
$('input[type=checkbox]').each(function () {
$('input[name='+n+']').attr('checked', true);
});
});
Substr is the array filled with names. substr = {'a', 'b', 'c', 'd'} .The above code does not work. please help
Upvotes: 0
Views: 454
Reputation: 87073
I think substr = {'a', 'b', 'c', 'd'}
should be substr = ['a', 'b', 'c', 'd']
.
jQuery.each(substr, function(i, val) {
// val = a, b, c... etc
$('input[type=checkbox][name="'+ val +'"]').attr('checked', true);
});
Upvotes: 2