0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ノードをbodyタグに挿入するなら、jsファイルの読み込みはbody開始タグより下で

Last updated at Posted at 2021-04-28

はじめに

ノードの作成、挿入を勉強しました。appendChildって難しい
以下ありがたい参考ページ
【DOM基礎】要素内容の取得・設定/ノードの作成・挿入・削除

appendChildがnull

今までhtmlファイルのheadタグでjsファイルを読み込んでいましたが、
挿入箇所、例えば

document.body.appendChild(container);

とbodyタグの中に挿入するときは、bodyタグの開始以降に記述しないと
Cannot read property 'appendChild' of null
挿入先がないと怒られます。

appendChildがundefined

挿入先の指定が

document.body.appendChild(container);

または

id名.appendChild(container);

でしかできませんでした。
クラス名やタグ名を指定するのは無理そう?

さいごに

jsファイルの読み込み場所の正解がわかりません。body終了タグの直前が丸いのでしょうか。

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?