I'm creating a web app in which users can bookmark certain places.
For this I've created a span
element which initially has a class no-bookmark
. Whenever a user clicks this span element I would check whether the span has the above class or not. If it has it means the user wants to bookmark the place and I would send a ajax request to server and then change the class to has-bookmark
.
If when the user clicks the span and it doesn't have the class no-bookmark
, then I assume that the user wants to delete the bookmark, and send a request for that to the server.
Is there a better way to maintain state, or is this method good enough?