質問編集履歴

1

書式の改善

2023/03/13 01:42

投稿

helpmee88
helpmee88

スコア4

test CHANGED
File without changes
test CHANGED
@@ -78,5 +78,30 @@
78
78
  // th要素をtr要素に追加
79
79
  trElem.appendChild(cellElem);
80
80
  ```
81
+ ### 修正内容と現在の状況
82
+ ■現在のHTML状況
83
+ ```html
84
+ <thead id="p-thead">
85
+ <tr>
86
+ <th class="__description" id="th-1">品番 / 品名 色 サイズ</th>
87
+ <th class="__price">
88
+ <div class="__total">販売価格</div>
89
+ <div class="__detail">(単価 × 入数)</div>
90
+ </th>
91
+ <th class="__order" id="th-3">必要数</th>undefined
92
+ </tr>
93
+ </thead>
94
+ ```
95
+ ■適応したJavaScript
96
+ ```js
97
+ // thead要素を取得
98
+ var theadElem = document.getElementById('p-thead');
99
+ // th要素を追加
100
+ var cellElem = document.querySelector('#th-3').after(cellElem);
101
+ // th要素にテキストを追加
102
+ cellElem.appendChild(document.createTextNode('セル'));
103
+ // th要素をtr要素に追加
104
+ trElem.appendChild(cellElem);
105
+ ```
81
106
 
82
107