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

121
Views
Javascript: Unable to pull from localStorage

Making a todo list for a class project - able to get the item to "add" and append to the list, but when you refresh the page, the item returns as undefined. Checking localStorage.todo, I see it pulling part of the values I need, but aren't in use yet, but not the actual innerText. I started adding bits for a line-through to check off completed items and a remove button, but that was commented out and hopefully isn't impacting things - was trying to isolate the error.

I'm guessing my issue is something in the localStorage.setItem, but I'm not sure what it would be. I've tried changing the newTodo.innerText value to other variables in use but nothing returns. Below returns an input value I enter, but again, is lost when the page refreshes.

const todoForm = document.querySelector('#todoForm');
const todoList = document.querySelector('#todoList');
let todoItem = document.querySelector('#todoItem');

// Pull from storage
const savedList = JSON.parse(localStorage.getItem('todo')) || [];
for (let i = 0; i < savedList.length; i++)
{
let newTodo = document.createElement('li');
newTodo.innerText = savedList[i].task;
todoList.appendChild(newTodo);

}

// Add Item
todoForm.addEventListener('submit', function(e){
    e.preventDefault();
    let newTodo = document.createElement('li');
    let newItem = document.querySelector('#todoItem').value;
    newTodo.innerText = newItem;
    todoForm.reset();
    todoList.appendChild(newTodo);

// Clear Form Field on submit and storage  

    savedList.push({ task: newTodo.innertext, isCompleted: false });
    localStorage.setItem('todo', JSON.stringify(savedList));

});
// Add Remove Button
    // let removeItem = document.createElement('button');
    // removeItem.innerText = "Remove";
    // newTodo.append(removeItem);

// Strike through item or remove item
// todoList.addEventListener('click', function(e){
//     if (e.target.tagName === 'BUTTON'){
//         e.target.parentElement.remove();
//     }
//     else if (e.target.tagName === 'LI'){
//         e.target.style.textDecoration = 'line-through';
//     }  
 
// });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

camelcase is wrong not innertext but innerText

savedList.push({ task: newTodo.innerText, isCompleted: false })
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!