Skip to content

Commit c7c8bb3

Browse files
authored
イベントの演習のヒントを改訂 (#726)
1 parent a1e7add commit c7c8bb3

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

docs/1-trial-session/14-events/index.mdx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,23 @@ greetButton.onclick = clicked();
8383

8484
<video src={projectMovieForDom} muted controls />
8585

86-
<Details summary={<summary>ヒント1:文字列の表示</summary>}>
86+
:::info[文字列の表示]
8787

88-
さっきは文字列の表示に `document.write()` を使いましたが、これでは文字色やサイズが変えられません。
89-
こんな書き方ならそれもできますが、あまりに乱暴ですよ。
88+
`document.write` 関数を使うと、画面上にあったボタンが消えてしまいます。また、文字色や文字サイズを変えることも困難です。
9089

91-
```javascript
92-
document.write("<div style='color:red; font-size:40px'>Hello world!</div>");
93-
```
94-
95-
HTML 要素を JavaScript で操作する方法は前回の「DOM」の章で扱っています。
90+
`document.write` 関数の代わりに、先ほどの DOM の章で扱った方法を使って HTML 要素を JavaScript で操作するとよいでしょう。
9691

97-
</Details>
98-
99-
<Details summary={<summary>ヒント 2: HTMLファイルに…</summary>}>
92+
:::
10093

101-
`<button>` タグの HTML 属性を書き換えるとボタンの中に `Hello world!` を表示してしまいます。
94+
:::info[`Hello World!` を表示する場所]
10295

103-
HTML ファイルに一工夫が必要です。空の `<div>` タグを用意してあげましょう
96+
`document.write` 関数を使わずに「`Hello World!` を表示する」という挙動を実現するためには、あらかじめ中身のない HTML 要素を置いておき、その要素の `textContent` プロパティを操作するとよいでしょう
10497

10598
```html
10699
<div id="greeting"></div>
107100
```
108101

109-
</Details>
102+
:::
110103

111104
<Answer title="びっくり箱">
112105
```html title="index.html"

0 commit comments

Comments
 (0)