I have an array in js that contains some name of checkbox i want to set checked. The problem is i cannot do it properly and i dont know why i'm wrong This is my code
var array = ['one','two word','three'];
for(var i = 0; i < array.length;i++)
$(':checkbox[value="'+array[i]+'"]').prop('checked', true);
With this HTML
<input type="checkbox" name="one[]" value="two word">
<input type="checkbox" name="one[]" value="four">
<input type="checkbox" name="one[]" value="one">
With this code my checkbox remain uncheked, can someone tell me why?
Aucun commentaire:
Enregistrer un commentaire