teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

.

2023/03/13 02:16

投稿

int32_t
int32_t

スコア21933

answer CHANGED
@@ -4,4 +4,8 @@
4
4
  cellElem.textContent = 'セル';
5
5
  document.querySelector('#th-3').after(cellElem);
6
6
  ```
7
+ または
8
+ ```js
9
+ document.querySelector('#th-3').insertAdjacentHTML('afterend', '<th>セル</th>');
10
+ ```
7
- でいいのではないでしょうか。
11
+ などでいいのではないでしょうか。

1

.

2023/03/13 01:58

投稿

int32_t
int32_t

スコア21933

answer CHANGED
@@ -1,5 +1,7 @@
1
1
  既存の<tr>に追加したいのに `insertRow()` (新たな<tr>を挿入する)はおかしいですね。
2
2
  ```js
3
+ const cellElem = document.createElement('th');
4
+ cellElem.textContent = 'セル';
3
5
  document.querySelector('#th-3').after(cellElem);
4
6
  ```
5
7
  でいいのではないでしょうか。