Question

Is there a way to assign a hidden value to a table cell? I would like to assign a certain value, an integer or a string to a table cell, so I can append and edit this value in javascript by using the id.

Était-ce utile?

La solution

Try HTML5's data api. You can set an attribute on the cell:

<td id="cell1" data-value="1">One</td><td id="cell2" data-value="2">Two</td>

You can then use:

document.getElementById('cell1').dataset.value;

Autres conseils

You can attach an attribute named 'data-' fowlloed by anything to any DOM node. Use the standard attribute access and change functions to read and write the value which will of course be a string.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top