So in details, my button works when you first time click on it, for example there's button "MARK" and when you click on it it should do ajax stuff (post it to my server etc, which is fine (first time)) also it should change the button class so it can behave like a "UNMARK" button (similar to facebook like/unlike system) and so I can unmark it if I accidently marked it. But it just does not work, button style changes, in inspector I can see that class is successfully changed to "unmark_message" too, but that new "unmark" button is not working at all. When I click on it nothing is happening, it just won't trigger the ajax action again.

You have two functions here. One function marks a button, the other function unmarks a button.

The problem with your code is that it only attaches one of those two functions to each button, meaning that each button only has the ability to either be marked (if it was originally unmarked) or unmarked (if it was originally marked).

You want to attach both functions to each button, and call the appropriate handler depending on the state of the button.