jQuery: Toggling between 3 classes (initially)

后端 未结 8 558
你的背包
你的背包 2020-11-29 09:32

I\'ve seen several posts here on SO but they are too specific in functionality and structure, and what I\'m looking for is something more universal that I or anyone can use

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 10:28

    You can do this :

    $('.toggle').click(function () {
      var classes = ['class1','class2','class3'];
      $('div').each(function(){
        this.className = classes[($.inArray(this.className, classes)+1)%classes.length];
      });
    });
    

    Demonstration

提交回复
热议问题