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

137
Views
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 answers
Answer question

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 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!