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

135
Views
How to delete specific item from local storage on click of button in todo app

How can i make a delete function that deletes the specific list from local storage when delete button is clicked and update the data. I am a beginner and i have no idea how i can make this happen. I have tried to look for solution by watching video but i couldn't find solution that i can understand.

let input = document.querySelector('input');
let btn = document.querySelector('button');
let ul = document.querySelector('ul');

let arr = getItem() || [];

arr.forEach(renderItem);

function addItem() {
  let inVal = input.value;

  if (inVal === '') return;
  renderItem(inVal);
  arr.push(inVal);
  setItem(arr);

  input.value = '';
  input.focus();
}

btn.addEventListener('click', () => {
  addItem();
});

window.addEventListener('keydown', e => {
  if (e.key === 'Enter') {
    addItem();
  }
});

function renderItem(render) {
  let li = document.createElement('li');
  li.innerText = render;
  let del = document.createElement('button');
  del.innerText = 'delete';
  del.setAttribute('class', 'delete');
  li.append(del);
  ul.append(li);
}

function setItem(set) {
  localStorage.setItem('name', JSON.stringify(arr));
}

function getItem() {
  let result = localStorage.getItem('name');
  return JSON.parse(result);
}
about 4 years ago · Juan Pablo Isaza
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!