Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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 Respuestas
Responde la pregunta

0

camelcase is wrong not innertext but innerText

savedList.push({ task: newTodo.innerText, isCompleted: false })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda