Jquery Onclick not happening second time

前端 未结 4 713
轻奢々
轻奢々 2021-01-20 10:38

I\'m a bit confused as to why this isn\'t working; I assume that because I\'m adding the class and its not being added back into the collection I\'m not sure.

Here i

4条回答
  •  囚心锁ツ
    2021-01-20 11:14

    You can change your code like this

    $(document).on("click", ".clickable", function(){
           var $this = $(this);
           if ($this.hasClass('optional')) {
               $this.removeClass('optional').addClass('selected');
           }
           else if ($this.hasClass('selected')) {
                $this.removeClass('selected').addClass('rejected');
           }
           else if ($this.hasClass('rejected')) {
                $this.removeClass('rejected').addClass('optional');
           }
           return false;    
    });
    

提交回复
热议问题