Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save contenteditable input to a variable so I can print it on screen

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>
like image 424
Yiannis Avatar asked Jan 18 '26 07:01

Yiannis


1 Answers

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
}
like image 53
EvgenyKolyakov Avatar answered Jan 20 '26 23:01

EvgenyKolyakov