1
2

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

JavaScriptの基礎~クリックしたとき⇒色を変える など

Last updated at Posted at 2019-07-11

#JavaScripの基礎
コピペして使ってください。
###クリックしたとき⇒色を変える

sample.js
//要素の取得 → クリックされたとき
document.getElementById('target').addEventListener('click',function(){
  //要素の取得 → 背景色を変える
  document.getElementById('target').style.background='pink';
});

###その他の処理

sample.js
//クリックしたとき⇒クラスを追加する
document.getElementById('target').classList.add('circle');
//クリックしたとき⇒クラスがついていたら外す、外れていたらつける
document.getElementById('target').classList.toggle('circle');
1
2
1

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?