LoginSignup
0
0

JavaScriptのclassListについて

Last updated at Posted at 2023-07-28

classListとは

要素のクラスを追加、削除、参照、操作するプロパティ

getAttribute使うより断然簡単

メゾット 内容 使い方
.add() classを追加 h1.classList.add('red');
.remove() classをはずす h1.classList.remove('red');
.toggle() クラスが含まれてたら削除、クラスが含まれてなかったら追加 h1.classList.toggle('red');
.contains() 特定のclassが設定しているか確認 h1.classList.contains('red');→true
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