fonjeekay fonjeekay - 22 days ago 9
HTML Question

Get HTML content from textarea with TinyMCE 4

I have a problem with TinyMCE 4 - I can't get HTML content from textarea. I am using the following code:

<textarea id="tiny">some text</textarea>
<a id="click" href="#">click</a>
<script>
$(document).ready(function () {
$("#click").click(function(e){
e.preventDefault();
var content=tinymce.get('content id').getContent();
console.log(content);
});
});
</script>


And as a result I'm getting this:

enter image description here

Question is how to get HTML content from
<textarea>
?

Answer

the id of the textarea is "tiny" not "content id"...

<textarea id="tiny">some text</textarea>

try changing...

var content=tinymce.get('content id').getContent();

to...

var content=tinymce.get('tiny').getContent();