Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  111] [ 5]  / answers: 1 / hits: 35831  / 10 Years ago, tue, november 25, 2014, 12:00:00

I had this problem when I get the value from a div:



function sync(){
var n1 = document.getElementById('editor').value;
alert(n1);
var n2 = document.getElementById('news');
n2.value = n1;
}


div with id editor looks like this:



<div class='message'  id='editor' contenteditable=true onkeyUp='sync()' style=color: black></div>


When I put something in that div it will alert me undefined and that will also come in the textarea i paste it in too. So the problem is obviously by this:



var n1 = document.getElementById('editor').value;


What am I doing wrong?


More From » html

 Answers
2

Try this



var n1 = document.getElementById('editor').innerHTML; // or innerText, or textContent

[#68705] Saturday, November 22, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shelbiec

Total Points: 101
Total Questions: 106
Total Answers: 106

Location: Ivory Coast
Member since Fri, Oct 8, 2021
3 Years ago
;