HTMLTableCellElement: cellIndex ããããã£
Baseline
åºãå©ç¨å¯è½
ãã®æ©è½ã¯åºãå®è£ ããã¦ãããå¤ãã®ãã¼ã¸ã§ã³ã®ç«¯æ«ããã©ã¦ã¶ã¼ã§åä½ãã¾ãã2015å¹´7æä»¥éããã¹ã¦ã®ãã©ã¦ã¶ã¼ã§å©ç¨å¯è½ã§ãã
cellIndex 㯠HTMLTableCellElement ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®èªã¿åãå°¾å°ç¨ããããã£ã§ãè¡ (<tr>) ã®ä¸ã«ãããã»ã«ã®ä½ç½®ã表ãã¾ããæåã®ã»ã«ã®ã¤ã³ããã¯ã¹ã¯ 0 ã§ãã
å¤
ã»ã«ã®ã¤ã³ããã¯ã¹ãè¿ãã¾ããã»ã«ãã©ã®è¡ã«ãå±ãã¦ããªãå ´å㯠-1 ãè¿ãã¾ãã
ä¾
ãã®ä¾ã§ã¯ãtbody ã® 1 è¡ç®ã®ãã¹ã¦ã®ã»ã«çªå·ã«ã©ãã«ã追å ãã¾ãã
HTML
html
<table>
<thead>
<tr>
<th>åå</th>
<th>ä¾¡æ ¼</th>
</tr>
</thead>
<tbody>
<tr>
<td>ããã</td>
<td>$2</td>
</tr>
<tr>
<td>ç±³</td>
<td>$2.5</td>
</tr>
</tbody>
</table>
JavaScript
js
const rows = document.querySelectorAll("tbody tr");
const cells = rows[0].cells;
for (const cell of cells) {
cell.textContent = `${cell.textContent} (ã»ã« #${cell.cellIndex})`;
}
çµæ
仿§æ¸
| 仿§æ¸ |
|---|
| HTML > # dom-tdth-cellindex > |