0

I am extracting content from an HTML textarea using JS, in order to then put it into a <div>. Now, I know the content is going to be valid HTML - so I assumed that if I set it as the innerHTML of another element it would be parsed by the browser - but it's not. I'm getting the plain string (with tags and all) on the screen.

This is basically my script:

var txt = document.getElementById("contentTextArea").innerHTML; //Get the content
document.getElementById("contentOutput").innerHTML = txt;

Here's the HTML, just to be sure:

<textarea name="content" id="contentTextArea">
<p>Text...</p>
</textarea>

What am I doing wrong? Is there another way of doing this? Thanks!

2 Answers 2

3

var txt = document.getElementById("contentTextArea").value; //Get the content

Sign up to request clarification or add additional context in comments.

Comments

2

Textareas support value not innerHTML. YOu should do this...

document.getElementById("contentTextArea").value;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.