Toggle between 3 classes using toggleclass

倖福魔咒の 提交于 2019-11-29 07:57:30

Example fiddle: http://jsfiddle.net/KdfEV/

This code will allow you to cycle through a sequence of defined classes

$('.one, .two, .three').click(function() {                             
    this.className = {
       three : 'one', one: 'two', two: 'three'
    }[this.className];
});
$('.one, .two, .three').click(function(){                             
        $(this).toggleClass("one, two, three");
    });

The safest way would be to remove unwanted classes and add the required class:

// Switch to class 'three'
$(this).removeClass('one').removeClass('two').addClass('three');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!