Search code examples
javascriptinnerhtmlgetelementbyid

innerHTML on keypress - cannot get content


I have a function which should grab the innerHTML of a textarea when the enter key is pressed.

The function seems to work with the key press, however the following line returns nothing:

var currentHTML = document.getElementById("postcontent").innerHTML;

I can't work out what's wrong with the line as it remains empty.

I've created a JS fiddle. Type something in the box and press enter, it should give you some console messages. You'll see that currentHTML remains empty when it should be grabbing the content.

http://jsfiddle.net/w4L7c2qh/1/


Solution

  • Use value instead of innerHTML for textarea.

    Updated you demo: fiddle