3

I have a textarea and a resume/CV sample template on document.

On button event that template's HTML is the value of textarea.

I am doing it as below-

$(function(){
    $('#select-sample').click(function(){
    var sample=$('.ok').html();
        $('.summernote').val(sample);
    });

});

This is just a simple copy thing is happening in textarea, I am picking up an HTML of template and copying it into textarea.

My question-

How do I render that HTML template in textarea as it is rendered in document. I don't want rendered HTML.

Why won't Textarea render this HTML template when all related css classes are attached within document itself?

Fiddle for this

Manoz
  • 6,507
  • 13
  • 68
  • 114
  • try this: $('.summernote').text(sample) or html(sample) – user1956570 Jan 07 '14 at 17:48
  • Possible duplicate of [Rendering HTML inside textarea](http://stackoverflow.com/questions/4705848/rendering-html-inside-textarea) – sirdank Nov 10 '15 at 17:03
  • Is there a way to potentially get the text (with html) inside of a textarea? Because whenever I do, and try putting the value in a
    , the tags don't show anything. It shows the tags still???
    – Taha Paracha Aug 16 '23 at 22:31

3 Answers3

3

Textarea elements are intended only for text input or manipulation, they have nothing to do with rendering. If you want to render, make a div: <div class="summernote"></div>. And change your jQuery to: $('.summernote').html(sample);

Sri--
  • 451
  • 3
  • 6
1

This is because the textarea element only shows text, if you wish to use markup you will need to make use of javascript and the contenteditable property or include a wysiwyg editor script, many of those can be easily found, although one of the most well known editors would be tinyMCE.

Entoarox
  • 703
  • 4
  • 8
  • In real scenario , I am using summernote texteditor for this job. But this editor doesn't seem to take values in it. – Manoz Jan 07 '14 at 17:54
  • @Manoz then you should have mentioned that you are using an editor, and you should look into the editors own API on how to input content. – Entoarox Jan 07 '14 at 18:06
0

You can use $('.summernote').code(sHTML);

http://hackerwins.github.io/summernote/features.html#api-code

Luntegg
  • 2,496
  • 3
  • 16
  • 31