質問編集履歴

1

試したことを追加

2021/07/04 10:31

投稿

mogumogu0u0
mogumogu0u0

スコア4

test CHANGED
File without changes
test CHANGED
@@ -64,7 +64,7 @@
64
64
 
65
65
  <head>
66
66
 
67
- <title>amity_sensei</title>
67
+ <title>Title</title>
68
68
 
69
69
  <meta charset="utf-8"/>
70
70
 
@@ -188,11 +188,85 @@
188
188
 
189
189
  【試したこと】
190
190
 
191
- 1.外部ファイルではなくhtml内のscriptに移動
191
+ **1.外部ファイルではなくhtml内のscriptに移動**
192
+
192
-
193
+ しかしエラーになったため、2を実行
194
+
193
-
195
+ Uncaught TypeError: Cannot read property 'addEventListener' of null
196
+
194
-
197
+ at index.html:15
198
+
199
+ ```html
200
+
201
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
202
+
203
+ <html lang="ja">
204
+
205
+
206
+
207
+ <head>
208
+
209
+ <title>Title</title>
210
+
211
+ <meta charset="utf-8"/>
212
+
213
+ <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
214
+
215
+ <!-- <link rel="icon" href="favicon.ico"> -->
216
+
217
+ <meta name="description" content="検索された時に表示されるタイトル">
218
+
219
+ <link rel="stylesheet" href="app.css">
220
+
221
+ <link rel="stylesheet" href="color.css">
222
+
223
+ <link rel="stylesheet" href="reset.css">
224
+
225
+ <meta http-equiv="Content-Script-Type" content="text/javascript">
226
+
227
+ <script>
228
+
229
+ document.getElementById('header-hamburger').addEventListener('click', function() {
230
+
231
+ document.getElementById('header-hamburger').classList.add('toggle')
232
+
233
+ })
234
+
235
+ </script>
236
+
237
+ </head>
238
+
239
+
240
+
241
+ <body>
242
+
243
+ <header class="header">
244
+
245
+ <div class="header-container">
246
+
247
+ <button id="header-hamburger"></button>
248
+
249
+ </div>
250
+
251
+ </header>
252
+
253
+ <script src="index.js"></script>
254
+
255
+ </body>
256
+
257
+ </html>
258
+
259
+ ```
260
+
261
+
262
+
195
- 2.DOMContentLoadedを使用
263
+ **2.DOMContentLoadedを使用**
264
+
265
+ htmlファイルscript内と
266
+
267
+ 外部jsファイルindex.js両方で試しましたが
268
+
269
+ 動作しませんでした。
196
270
 
197
271
  ```JavaScript
198
272
 
@@ -200,8 +274,6 @@
200
274
 
201
275
  document.getElementById("header-hamburger").addEventListener("click", function() {
202
276
 
203
- // document.getElementById("header-hamburger").classList.add("toggle")
204
-
205
277
  console.log('hey')
206
278
 
207
279
  })
@@ -209,3 +281,9 @@
209
281
  })
210
282
 
211
283
  ```
284
+
285
+
286
+
287
+ **3.Chrome設定を確認**
288
+
289
+ JavaScriptは有効になっていました。