Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
How can i add Local Storage to my todolist?

I am doing some practice javascript exercise. My project look like 'trello' but much soft and simple.

When i writing some notes to input, javscript adding note dynamically but if i refresh the page/chrome, all things gone or lost.

So i wanna apply localstorage on my project. How can i do it.

My Note project: https://codepen.io/daniel_134/pen/NWwYKyK[My Note project]1

var input = document.querySelector('#text-input');


document.querySelector("#ad-note-btn").addEventListener("click",  () => {
   if (input.value.length > 1) {
      // GET-INPUT-VALUE
      var getvalue = input.value;
      // CREATE-NEW-NOTE
      const newLi = document.createElement("textarea");
      newLi.value =  getvalue;
      newLi.className =  "note-li";
      // ADD-NEW-NOTE
      var ul = document.querySelector('#list-items');
      ul.appendChild(newLi);



      // EMPTY-INPUT-WHEN-CREATING-NEW-NOTES
      input.value = " ";
    
      //  DELETE-NOTES
      const dleLi = document.createElement("button");
      dleLi.textContent = "delete";
      dleLi.className = "list-btn";
      ul.appendChild(dleLi);
      dleLi.addEventListener("click", () => {
         newLi.remove();
         dleLi.remove();
         edLi.remove();
         saveLi.remove();
     })
    
   //   EDIT-NOTES
     const edit = () => {
       if( newLi.value.length > 0 ) {
          newLi.disabled = true; 
       } else {
          newLi.disabled = false; 
       }
     }
    
     edit()
    
    const edLi = document.createElement("button");
    edLi.textContent = "Edit";
    ul.appendChild(edLi);
    edLi.className = "list-btn";
    edLi.addEventListener("click", () => {
       if ( newLi.disabled = true ) {
          newLi.disabled = false; 
       }else {
          newLi.disabled = true; 
       }
    })
    
    const saveLi = document.createElement("button");
    saveLi.textContent = "save";
    ul.appendChild(saveLi);
    saveLi.className = "list-btn";
    saveLi.addEventListener("click", () => {
       edit();
    })

    
   } else {
      ul.appendChild();
   }


})

 
document.querySelector("#clear-btn").addEventListener("click", () => {
   input.value = " ";
})


2

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

it'll look like that , for example :

  • when you load your page .
  • load todoList var todoList = JSON.parse(localStorage.getItem('todo-list'))
  • and display it
  • when you add new element to your to-do list
  • var todoList = JSON.parse(localStorage.getItem('todo-list'));
  • 
           var new_todo = [{
                 title:'for example ...',
                 complete:false
           }];
           localStorage.setItem('todo-list',JSON.stringify(new_todo));
    
       }else{
           todoList.push({
                 title:'for example ...',
                 complete:false
           });
    
            localStorage.setItem('todo-list',JSON.stringify(todoList));
    
       }
    
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda