What HTML attribute should I use to name HTML elements that I want to address from Javascript. For example if I could use name:
<table id="some_table">
<tr>
<th name="date">Date</td>
<th name="time">Time</td>
<th name="name">Name</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
I could select them with jQuery like this:
$('#some_table th[name=time]')
This, however, is invalid, as name is not allowed for td. id must be unique, so I can’t use it either. class could affect the styling if there is a CSS class .time. Maybe something like data-name? What is the preferred way?
To expand on my comment, you don’t “need to give the td some attribute with the column name”. The standard way would be to get the column index from the column name, then retrieve all tds with this index.
For example if time is the second column (index 1), all the time tds are:
(JavaScript has native methods to traverse tables)