1
0

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 1 year has passed since last update.

document.getElementById()のメモ

Posted at

自分用の備忘録です。

取得したいHTMLのID

qiita(pタグ)
form(inputタグ)

基本的な使い方

main.js
//取得
qiita = document.getElementById("qiita")

テキスト取得&書き換え

main.js
//取得
qiita = document.getElementById("qiita")
//コンソールに出力
console.log(qiita.innerText)
//文字をHello Qiita!に書き換え
qiita.innerText = "Hello Qiita!"

取得の際に.innerTextを指定すると読み出しはできますが書き換えができません

inputタグを取得

main.js
//取得
form = document.getElementById("form")
//コンソールに出力
console.log(qiita.value)
//文字をHello Qiita!に書き換え
qiita.value = "Hello Qiita!"
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?