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

139
Visualizações
How to store and re-use local storage data using jQuery?

I am new to using local storage. Can anyone teach me how I can get the value I've placed in the textarea, and once I click the done button it will store in the .result class. Also once I've input again there's another it will store again in the .result class? Please anyone can help me with this?

$(".Done").on("click", function() {
  var test = $(".title").val();
  localStorage.setItem("title", test);
});
.result {
  color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="title"></textarea>
<div class="Done">Done</div>

<div class="result"></div>

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

0

To achieve your goal you need to do two things. Firstly set the text() of .result based on the value in the textarea when the button is clicked.

Secondly you need to check if the title is set in local storage when the page loads, and if it is, then set the value of .result with that content.

The logic would look like this:

let setResult = title => $('.result').text(title || '');

jQuery($ => {
  setResult(localStorage.getItem('title')); // set on load    

  $(".Done").on("click", function() {
    let title = $(".title").val();
    setResult(title); // set on click
    localStorage.setItem("title", title);
  });
});

Here's a working example in jsFiddle as the SO snippet editor is sandboxed and doesn't allow access to local storage.

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