0
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 3 years have passed since last update.

Javascript用語集

Posted at

5-3イメージの切り替え

:sunny:マッチする要素を全て取得する

document.querySelectorAll('CSSセレクタ')

例:const thumbs = document.querySelectprAll('.thumb');

:sunny:配列の各項目を繰り返し処理する(forEachメソッド)

配列.forEach(function(item,index){
  処理内容をここに書く
});

:sunny:Javascriptでdata-なんでも属性の値を切り替える

<タグ名 data-A(自由に決めて良い) = "img1.jpg">

取得した要素.dataset.A

item.onclick =function(){
  console.log(this.dataset.image);
}

属性の書き換えについて

:sunny:属性の値を読み取る

取得した要素.属性

:sunny:属性の値を書き換える

取得した要素.属性 = 値;
0
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
0
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?