Search code examples
javascriptjqueryhtmlckeditorckeditor4.x

How can I take HTML code from a textarea and then serve that to the CKEDITOR as setData?


I am trying to take data from a textarea element to serve that as setData to CKEDITOR but instead of getting the HTML code I am getting the html code as a string, It's not being rendered as HTML code. Please have a look over the code :

CKEDITOR.replace('editor', {
    height: 200
});
window.onload = function() {
    var html = $('textarea[name="venue_description"]').text();
    CKEDITOR.instances.editor.setData(html);
}

Here is the result what I am getting as :

enter image description here


Solution

  • Use val() instead of text()

    var html = $('textarea[name="venue_description"]').val();