jQuerybeast
jQuerybeast

Reputation: 14490

HTML 5 Local Storage: If value = "..." do function

I have an on/off button and I'm trying to set it's value with html 5 localstorage. On click, I added localStorage.setItem("button", "On");.

On document load: localStorage.getItem("button");

Now how can I say, if localstorage.item("button") value = On, do function. I'm using jQuery.

Thanks alot.

Upvotes: 0

Views: 473

Answers (1)

Marcelo Cantos
Marcelo Cantos

Reputation: 185852

The getItem method returns the value. You invoke it whenever you need the value:

if (localStorage.getItem("button") == "On") ...

BTW, just calling getItem when the document is loaded serves no purpose.

Upvotes: 1

Related Questions