I'm developing a website, that apply content editable feature to some pages, so I wanted to store it in local storage, but it only works for one element! I tried to use GetElementByClassName() and querySelectorAll(), but with no luck. Here is the code and any feedback is highly appreciated!
<header>
<section>
<div>
<h1 class="edit" contenteditable="true" title="Edit your trip name">Trip Name</h1>
<h3 class="edit" contenteditable="true" title="Edit your country name"> Country Name</h3>
<a href="" class="cd-btn" onclick="saveEdits()">Save</a>
</div>
</section>
</header>
<section>
<h2 title="Anything to add?">Trip Foucs</h2>
<div class="edit" contenteditable="True" title="Anything to add?"></div>
</section>
<script>
function saveEdits() {
//get the editable element
var editElem = (document.getElementsByClassName("edit"));
//get the edited element content
var userVersion = editElem.innerHTML;
//save the content to local storage
localStorage.userEdits = userVersion;}
function checkEdits() {
//find out if the user has previously saved edits
if(localStorage.userEdits!=null)
(document.getElementsByClassName("edit")).innerHTML =localStorage.userEdits;}
</script>
Thanks, Maryam