josef’s diary

10,000時間の法則を実験しています。興味:★★プログラミング/ 統計/ ★ギター/タイ語

innerHTMLとtextContentの違い

結論

  • innerHTML
    • HTMLの特殊文字(例:<,>のようにタグとして機能する文字)を機能させる
  • textContent

See the Pen ZEbQOYa by shimizu517 (@shimizu517) on CodePen.

ポイント

  • document.getElementById('hello'): html内のid="hello"を持つ要素を指定
  • hello.textContent = "hello";
    • 要素内にテキストを入れる。

※HTMLにおいてテキストとはタグの中の文字列のこと