I have this code and I want to save a contenteditable text to a variable so i can print it on screen. HTML:
function saveEdits() {
//get the editable element
var editElem = document.getElementById("myText").value;
document.getElementById("update").innerHTML=editElem;
//write a confirmation to the user
}
<h1 id="myText" contenteditable="true">Title</h1>
<input type="button" value="save edits" onclick="saveEdits()"/>
<p id="update"></p>
I'd try using innerHTML:
function saveEdits() {
//get the editable element
document.getElementById("update").innerHTML = document.getElementById("myText").innerHTML;
//write a confirmation to the user
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With