Get value from div with javascript: Always get undefined

html, javascript, undefined

Solution

Try this

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

Problem

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?

Original source

Related problems