7
14

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を学ぶ③(toggle 定数を使ってみよう♪)

Posted at
<script>
  'use strict';
  const hitokage = document.getElementById('target');

  hitokage.addEventListener('click',function(){
     hitokage.classList.toggle('circle')
  });
</script>

今回、新しく勉強したのは、toggle定数です♪
※定数については、ある程度勉強しているので、説明は割愛します。

<説明>
addではなく、toggleに変更したことで、
CSSクラスがついていなかったらつける
CSSクラスがついていたら外す という状態になります♪

#toggleについて

toggleは、クリックなどの同じ操作によって、
二つの状態を交互に切り替えられるような仕組みのことだそうです。
メディアプレーヤーの再生と一時停止を切り替えるボタンなどによく使われるみたい:tv:

今回はアレンジなしにしますが、
toggleの使い方を検索するとメニューの表示・非表示を、
jQueryで使用することが多そうです(^^)
以下の記事がすごく分かりやすかったので、ご参考までに♪
jQueryのtoggleで表示・非表示を切り替えてみよう

では、続きは次回にしていきましょう:angel:

7
14
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
7
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?