0
1

More than 3 years have passed since last update.

[memo]innerHTML

Last updated at Posted at 2021-01-24

innerHTML について

innerHTMLを使用すると、HTML要素の取得や書き換えを行うことができます。
例えば、以下のように指定した要素の文字列を取得・操作することができます。

html
<div class="contents" id="apple">りんご</div>
javascript
const apple = document.getElementById("apple")

console.log(apple)
// => <div class="contents" id="apple">りんご</div>

console.log(apple.innerHTML)
// => りんご

apple.innerHTML = "青リンゴ"
console.log(apple.innerHTML)
// => 青リンゴ

apple.innerHTML = "青リンゴ"の意味は
apple.innerHTML へ 青リンゴ を定義するというようなもの。これにより
console.log(apple.innerHTML)を実行すると青リンゴが出力される

0
1
0

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