「jQuery」toggleClass()でボタンを押した時にクラスを付与する
説明
ボタンを押した時にクラスを付与する場合は toggleClass() を使用します。
サンプルコード
$(function(){
$('.button').click(function() {
$(this).next().slideToggle();
$(this).toggleClass('active');
}).next().hide();
});
$(function(){
$('.button').click(function() {
$(this).next().slideToggle();
$(this).toggleClass('active');
}).next().hide();
});
$(function(){ $('.button').click(function() { $(this).next().slideToggle(); $(this).toggleClass('active'); }).next().hide(); });
説明
クラス名activeを必要なクラスに変更可能です