I have a table that has a date input
<td style="background-color:#c6efce"><input type="text" id="datepicker0"></td>
<td style="background-color:#c6efce"><input type="text" id="datepicker1"></td>
<td style="background-color:#c6efce"><input type="text" id="datepicker2"></td>
<td style="background-color:#c6efce"><input type="text" id="datepicker3"></td>
<td style="background-color:#c6efce"><input type="text" id="datepicker4"></td>
I am trying to access it via for the first one
<script>
$(function() {
$( "#datepicker0" ).datepicker({
showButtonPanel: true
});
});
</script>
How do I access everything?
You could use the “attribute starts-with” selector:
That selector will match any
inputelement whoseidvalue starts with “datepicker”. An alternative would be to give all the required elements a common class.You can also select multiple elements by
idusing a comma-separated list:But that’s not particularly scalable if you ever need to add more inputs.