LoginSignup
0
0

More than 3 years have passed since last update.

document.getElementsByTagNameを使うと配列のような形式で戻ってくる

Last updated at Posted at 2019-09-12

自分学習用メモ。
document.getElementsByTagName(タグ名)を使うと配列のような形式が変数に入る。

sample.js
var button = document.getElementsByTagName('button');
console.log(button);

スクリーンショット 2019-09-13 0.00.53.png

ボタンの色を変えたい場合は、直接styleのプロパティのbackgroundColorに色を入れてみる.

sample.js
var button = document.getElementsByTagName('button');
button[0].style.backgroundColor = '#f00';

スクリーンショット 2019-09-13 0.03.41.png

0
0
2

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
0