I have elements like this on a html page:
<input id="serial[301888][0]" type="hidden" value="51.0100|T2-QQQ" name="serial[301888][0]">
<input id="serial[301888][1]" type="hidden" value="5.0900|T2-WWW" name="serial[301888][1]">
<input id="serial[301888][2]" type="hidden" value="11.1100|T2-XXX" name="serial[301888][2]">
<input id="serial[301888][3]" type="hidden" value="22.5600|T2-YYY" name="serial[301888][3]">
<input id="serial[301888][4]" type="hidden" value="10.2300|T2-ZZZ" name="serial[301888][4]">
Without using jQuery, how could I get all these elements into an array?
You can combine JavaScript's document.querySelectorAll
with CSS's ^=
attribute selector:
document.querySelectorAll('[id^="serial[301888]"]');
This will generate an array of all elements whose id
attributes start with "serial[301888]"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With