Reputation: 43
Hi i got a question how can i display a saved user content value onclick into another div this are my user edit save scripts
<script>
function saveEdits() {
//get the editable element
var editElem = document.getElementById("edit");
//get the edited element content
var userVersion = editElem.innerHTML;
//save the content to local storage
localStorage.userEdits = userVersion;
//write a confirmation to the user
document.getElementById("update").innerHTML="Änderungen gespeichert!";
}
function checkEdits() {
//find out if the user has previously saved edits
if(localStorage.userEdits!=null)
document.getElementById("edit").innerHTML = localStorage.userEdits;
}
</script>
now i want the stored user value be displayed in a div with the id code1 onclick of a button somebody a fix idea? Edit:
The Usercontent should be displayed in this div
<div id="code1" class="code">User Content Value</div>
after a click on this Button
<a href="#" id="codebtn1" class="button" style="display: block;"><span class="fa fa-code"></span> Quellcode anzeigen</a>
Upvotes: 0
Views: 769
Reputation: 26
This should do the job (without jQuery):
function showEdits(){
if(localStorage.userEdits!=null){
var target = document.getElementById("code1");
target.innerHTML = localStorage.userEdits;
}
}
var button = document.getElementById("codebtn1");
button.addEventListener("click", showEdits);
Upvotes: 0
Reputation: 1150
Try this
HTML
<div id="pwdDescription">
</div>
<a href="#" id="codebtn1" class="button" style="display: block;"><span class="fa fa-code"></span> Quellcode anzeigen</a>
SCRIPT
$(document).ready(function () {
$('#codebtn1').click(function (e) {
document.getElementById("pwdDescription").innerHTML = "Value";
});
});
Demo http://jsfiddle.net/bk7Na/2/
Upvotes: 0