質問

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.

役に立ちましたか?

解決

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;

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top