I need to check a certain selection of checkboxes using JavaScript. All these checkboxes have the letter a at the beginning of the id and other checkboxes have a different letter.I also don’t know how many of these checkboxes there will be since they are created dynamically
<input type="checkbox" id="a1" />
Now if I click on a button a JavaScript function is called and these checkboxes with letter a at beginning of id’s should be checked, is this possible and how?
Is there something that can be used in conjunction with document.getElementById('a').checked?
You can get the checkboxes and loop through them, like this:
You can give it a try here
Edit: a bit cleaner to use
.charAt(), good call and thanks Tim!