There is a simple code:
$('.like').on("click", function(){ console.log("click_l"); $(this).addClass('unlike'); }); $('.unlike').on("click",function(){ console.log("click_u"); $(this).addClass('like'); }); <button class="btn btn-default card_body_like like_div unlike"><div></div></button> As you can see, the unlike class initially (it has its own style, lights, like in like). The problem is that it constantly displays click_u in the console, that is, even when the unlike class has disappeared, and instead of it, put like - it accepts this button as an element with class unlike