blog
copyright ©
creamu Inc. All Rights Reserved.
art direction & design: Kunitaka Kawashimo
code, interaction & photography: creamu Inc.
category: Technology

jQueryでクラスの追加/削除をする方法

Pocket

jQueryでクラスの追加/削除をするには、以下のように書きます。

$(function() {
$(‘#btn’).on(‘click’, function() {
$(this).toggleClass(‘is-active’);
});
});

対象の要素に指定したclassがなければ追加、あれば削除されます。


Warning: A non-numeric value encountered in /home/users/1/creamuinc/web/creamu.co.jp/wp/wp-content/plugins/wp-social-bookmarking-light/vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 43

Warning: A non-numeric value encountered in /home/users/1/creamuinc/web/creamu.co.jp/wp/wp-content/plugins/wp-social-bookmarking-light/vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 43

Warning: A non-numeric value encountered in /home/users/1/creamuinc/web/creamu.co.jp/wp/wp-content/plugins/wp-social-bookmarking-light/vendor/twig/twig/lib/Twig/Environment.php(462) : eval()'d code on line 43