'jQuery Summernote - Get text back into editor
I got problems getting text back into the summernote editor.
I already tried (but did not work):
$("#EDITsummernote").innerHtml = 'test';
How to do that?
Solution 1:[1]
Since v0.7.0 code() has been deprecated and removed (same story for destroy() method).
You must use $(".summernote").summernote("code", "your text");
Reference: https://summernote.org/getting-started/#get--set-code
After v0.7.0, direct jquery methods,
destroyandcodewere removed for avoiding conflict with other jquery libraries. You can call this methods with summernote api.
Solution 2:[2]
$(".summernote").code("your text");
Solution 3:[3]
Insert Text:
$('#summernote').summernote('editor.insertText', 'hello world');
You can use this line if you want to set (paste) HTML code in editor:
$('#summernote').summernote('editor.pasteHTML', '<b>hello world</b>');
Bonus
Clear all editor content:
$('#summernote').code("");
Solution 4:[4]
To set:
$('#summernote').summernote('code', '<b> hello world </b>');
To get:
var get_code = $('#summernote').summernote('code');
Documentation: http://summernote.org/getting-started/#get--set-code
Solution 5:[5]
To set text in the summernote editor:
$('#summernote').summernote('editor.insertText', 'hello world');
Solution 6:[6]
None of the Solutions works for me until I did this.
<textarea name="description" class="form-control summernote_rpt summernote_custom"></textarea>
Let's say you have initialized summernote something like this in which I have two classes
.summernote_custom was used
$('.summernote_rpt').summernote(options);
when the entire page loads and when I wanted to update the summernote value using js I used
$('.summernote_rpt').summernote('code','data');
Solution 7:[7]
$('#summernote').html(escape($('#summernote').summernote('code', 'some')));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | frobinsonj |
| Solution 2 | linktoahref |
| Solution 3 | |
| Solution 4 | |
| Solution 5 | |
| Solution 6 | Abhi Burk |
| Solution 7 | Jorge J V. L |
