javascript - How to make contenteditable save permanently and globally? - Stack Overflow

PHOTO EMBED

Tue Nov 22 2022 18:09:48 GMT+0000 (Coordinated Universal Time)

Saved by @refundipartment #html

<!DOCTYPE html>
<html>
<head>
<script>
 
  var version = 0;
  
function saveEdits() {
  
  var editElem = document.getElementById("edit");
  version = localStorage.getItem("v");
  var versionTxt = document.createTextNode("Version " + localStorage.getItem("v"))
  document.body.appendChild(versionTxt);   
  version++
  
  localStorage.setItem("v", version);
  localStorage.setItem("Elm", editElem.innerHTML);
  
  
  
  document.getElementById("update").innerHTML="Edits saved!";
}

 var editedElem = document.getElementById("edit");
 var edits = localStorage.getItem("Elm");
 editedElem.innerHTML = edits;
 

</script>

</head> 

<body>
  <div id="edit" contenteditable="true">
 Edit me
</div>

<button onclick="saveEdits()">save edits</button>
<div id="update"> - Edit the text and click to save for next time</div>

</body>

</html>
content_copyCOPY

https://support.google.com/accounts/answer/7299973?hl=en-GB