Jquery Onclick not happening second time

前端 未结 4 720
轻奢々
轻奢々 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 10:58

    Not sure if you already know about this or not.... Check the jquery documentation on the .live() functionality. That way, you could do something like this.

    $('.optional').live('click', function () {
                    $(this).removeClass('optional').addClass('selected');
                    return false;
                });
    

    And then you don't have to worry about classes not existing at document load. As the classes change on the elements, they'll automatically be bound to.

提交回复
热议问题