I am trying to test if checkbox is checked. I have more inputs and they have different names. I managed to select the input but I can't seem to check if it wa selected. If I add to the condition '= true' it is checked once I load the page. If I leave it just .checked it doesn't do anything
-
Have I selected the input right? Please note I want to select it by name rather than id or class
-
Why is it that once the page loads my condition for if statement doesn't work?
<input type="checkbox" name="name1">
<input type="checkbox" name="name2">
<input type="checkbox" name="name3">
<input type="checkbox" name="name4">
const firstInput = document.getElementsByName('1');
if (firstInput[0].checked) {
console.log('checked');
}
Aucun commentaire:
Enregistrer un commentaire