I have some inputs as below:
<input type="hidden" id="selected_id-1" name="id[]" />
<input type="hidden" id="selected_id-2" name="id[]" />
<input type="hidden" id="selected_id-3" name="id[]" />
<input type="hidden" id="selected_id-5" name="id[]" />
The list can contain more than just 4 elements.
So, I would like to extract the highest number (in our case = 5) from the ids of elements named “id”.
Pure JavaScript needed.
EDIT: Thank you everybody who answered my question.
Assuming your elements might not be ordered by id, you’ll have to check them all to find the highest one.