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

209
Views
localStorage.getItem does not update the rows deleted in javascript. What can i do to enable this

localStorage.getItem does not update the rows deleted in javascript. What can i do to enable this.

when I refresh the page. I see the last data entered but when i delete a row. the deleted row is not is not stored

    enter code here

// const formEl = document.querySelector("form");
// const tbodyEl = document.querySelector("tbody");
// const tableEl = document.querySelector("table");
// localStorage.clear()

function onAddWebsite(e) {
  e.preventDefault();
  const website = document.getElementById("website").value;
  const url = document.getElementById("url").value;
  let data = document.querySelector("tbody").innerHTML += `
      <tr>
          <td>${url}</td>
          <td>${website}</td>
          <td><button class="deleteBtn">Delete</button></td>
      </tr>
  `;
  localStorage.setItem('data', data)
}

function onDeleteRow(e) {
  if (!e.target.classList.contains("deleteBtn")) {
    return;
  }

  const btn = e.target;
  btn.closest("tr").remove();

}

document.addEventListener('DOMContentLoaded', function() {
  document.querySelector('tbody').innerHTML = localStorage.getItem('data');
  document.querySelector('button').onclick = onAddWebsite;
  document.querySelector('table').onclick = onDeleteRow;
});
about 4 years ago · Santiago Trujillo
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!