Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Is there a way to know whether or not something is added to localStorage?

I want to have a button that toggles something in and out of localStorage (it's clicked once and it adds something to localStorage, it's clicked again and that something disappears from localStorage). I want to do something like the code below, but toggling "status" instead of setting it permanently.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Okay. I don't know I got you or not. Here is a solution..

First I'm taking a button :

<button>Toggle</button>

Then using some scripts to toggle (add, remove) the item inside of localsotrage.

<script>
const button = document.querySelector("button");
button.addEventListener("click", function(){
  const item = localStorage.getItem('info');
  if (!item){
    localStorage.setItem('info', 'Hello World')
  }else{
    localStorage.removeItem('info')
  }
})
</script>

inside of this script simple method has been implemented. At first I'm taking a value from localstorage. Inside of if/else condition when item value if falsy it will add item into localstorage. When it is truthy it will remove from localStorage.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!