Adrengski
Adrengski

Reputation: 97

Changing the text once clicked and preventing it to revert back to original text once the page is reloaded

I have a link that changes the text into something else once it's clicked. It's working fine and changes when clicked but once the page is refreshed, the text reverts back to the original text.

$('a.like-link').text('Unlike');

That's what I'm using by the way.

Is there any way to prevent the text from reverting back to the original text?

Upvotes: 0

Views: 72

Answers (2)

user938787
user938787

Reputation:

Two options;

  1. Doing it server side
    Useful links:

  2. Doing it with cookies
    Useful links:

Upvotes: 1

Interrobang
Interrobang

Reputation: 17434

You'll need to persist the new state somehow. You could use an AJAX request to update a database, or set a cookie, for example.

Upvotes: 2

Related Questions