File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
docs/1-trial-session/13-dom Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,12 @@ element.style.backgroundColor = "red";
5353
5454` document.createElement ` 関数は、引数に要素の種類を表す文字列を取り、その種類の新しい HTML 要素を作る関数です。
5555` document.createElement ` 関数の戻り値は、新しく作った HTML 要素に対応するオブジェクトです。
56- 下の例では、新しい ` button ` 要素を作っています。
56+ 下の例では、新しい ` span ` 要素を作っています。
5757中身のない空の要素が作成されるので、` textContent ` を ` Hello World! ` に設定してみましょう。
5858
5959``` js title="script.js"
60- const newButton = document .createElement (" button " );
61- newButton .textContent = " Hello World!" ;
60+ const newSpan = document .createElement (" span " );
61+ newSpan .textContent = " Hello World!" ;
6262```
6363
6464そして、` 要素1.appendChild(要素2) ` とすることで、要素1の子要素に要素2を追加し、画面に表示することができます。
@@ -71,13 +71,13 @@ newButton.textContent = "Hello World!";
7171``` js title="script.js"
7272const parent = document .getElementById (" parent-element" );
7373
74- const newButton = document .createElement (" button " );
75- newButton .textContent = " Hello World!" ;
74+ const newSpan = document .createElement (" span " );
75+ newSpan .textContent = " Hello World!" ;
7676
77- parent .appendChild (newButton );
77+ parent .appendChild (newSpan );
7878```
7979
80- これで、既存の ` div ` 要素の子要素に新しい ` button ` 要素が追加され、画面に ` Hello World! ` と書いてあるボタンが表示されます 。
80+ これで、既存の ` div ` 要素の子要素に新しい ` span ` 要素が追加され、画面に ` Hello World! ` と表示されます 。
8181
8282## 初級課題
8383
You can’t perform that action at this time.
0 commit comments