appenChildにより、要素の追加ができません。
html
1<!DOCTYPE html> 2<html lang="ja"> 3 <head> 4 <meta charset="utf-8"> 5 <title>Javascript Basics</title> 6 <style> 7 8 .box{ 9 width:100px; 10 height:100px; 11 background:gray; 12 } 13 14 .border-pink{ 15 border-bottom:5px solid pink; 16 } 17 18 </style> 19 </head> 20 <body> 21 22 <script src="js/main.js"></script> 23 24 </body> 25</html>
js
1'use strict'; 2{ 3 4 const h1 = document.createElement('h1'); 5 6 h1.textContent = 'Title'; 7 8 document.body.appenChild(h1); 9 10 11} 12
上記コードを実行しても「Title」の文字は表示されず、デバッグツールのElementsタブ内を確認しましたが、h1属性は追加されていません。
原因が分からないため、どなたかご教示頂けたら幸いです。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/31 18:14
2019/05/31 18:14