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

101
Views
Moving and keeping an element

Once I press "+" sign and the element is moved to the "destination" div, what would be the easiest way with the help of local storage to keep an "element" in the "destination" div after the page is refreshed?

function appendIt() {
  var element = document.getElementById("element");
  document.getElementById("destination").appendChild(element);
}
#destination {
  background-color:red;
}

#source {
  background-color:beige;
}
<div id="destination"></div>
<div id="source">
  <a id="element"href="#" onclick="appendIt()">One</a></div>

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

One way is to keep the innerHtml of that div in LocalStorage and on page refresh check if anything exists there and if exists append in the div.

about 4 years ago · Juan Pablo Isaza Report

0

As you mentioned with localStorage, you can add some flag in local storage inside appendIt() function. And on windows load event you can check if that flat is there in local storage and what value it have. Based on that value you can again call appendIt() as per requirement.

function appendIt() {
  // set value to local storage with key append
  localStorage.setItem("append", "true");
  var element = document.getElementById("element");
  document.getElementById("destination").appendChild(element);
}

// Add windows load event to check local storage
window.onload = (event) => {
  // check local storage for key append and if its value is true then call appendIt function
  if (localStorage.getItem("append") == "true") {
    appendIt();
  }
};
#destination {
  background-color: red;
}

#source {
  background-color: beige;
}
<div id="destination"></div>
<div id="source">
  <a id="element" href="#" onclick="appendIt()">One</a></div>

about 4 years ago · Juan Pablo Isaza Report

0

You want to create a deep clone before appending the element. This is achieved by calling cloneNode(true) on the element:

document.getElementById("destination").appendChild(element.cloneNode(true));
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!