Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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:

    <input type="button" value="save edits" onclick="saveEdits()"/>
    <p id="update"></p>```

and JS:

```function saveEdits() {
    //get the editable element
    var editElem = document.getElementById("myText").value;
    document.getElementById("update").innerHTML=editElem;
    //write a confirmation to the user
  }```

Thank you for your time.
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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
}
about 4 years ago · Juan Pablo Isaza Report

0

From what I understand you want this :

function saveEdits() {
    //get the editable element
    var editElem = document.getElementById("myText").value;
    document.getElementById("update").innerHTML=editElem;
    //write a confirmation to the user
    alert("your text have been saved");
  }
<input type="text" placeholder="type content here" id="myText">
<input type="button" value="save edits" onclick="saveEdits()"/>
    <p id="update"></p>

The text is stocked in the editElem variable.

about 4 years ago · Juan Pablo Isaza Report

0

Just change .value to .innerHTML .

function saveEdits() {
//get the editable element
var editElem = document.getElementById("myText").innerHTML;
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>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!