How do I programmatically retrieve content from a WYSIHTML5
editor?
Suppose the editor is instantiated as this:
var editor = new wysihtml5.Editor
(
$(this.el).find('textarea').get(0),
{
toolbar: "toolbar",
parserRules: wysihtml5ParserRules
}
);
i would like to get the editor's content on blur
event
editor.on
(
"blur",
function()
{
//what here?
}
);
How do I programmatically retrieve content from a WYSIHTML5
editor?
Suppose the editor is instantiated as this:
var editor = new wysihtml5.Editor
(
$(this.el).find('textarea').get(0),
{
toolbar: "toolbar",
parserRules: wysihtml5ParserRules
}
);
i would like to get the editor's content on blur
event
editor.on
(
"blur",
function()
{
//what here?
}
);
Share
Improve this question
edited Jan 22, 2019 at 6:08
Cœur
38.7k26 gold badges202 silver badges277 bronze badges
asked Jun 11, 2012 at 19:07
DalenDalen
9,0064 gold badges49 silver badges53 bronze badges
1
- You can either look at the docs of that editor or retrieive it from rendered output of it by inspecting through console. – Sarfraz Commented Jun 11, 2012 at 19:09
2 Answers
Reset to default 11It's much better to use the API
editor.getValue()
(@dalen mentioned this in the comment above)
Here is how (using jQuery here):
$('iframe').contents().find('.wysihtml5-editor').html();
To find text instead, use text()
instead of html()
.
FYI:
- I jQuerified this demo page of it using jQueryify bookmarklet
- Entered some text in editor
- typed above code at console and output was entered text
In your application, you won't need the jQueryify bookmarklet, I used it to inject jQuery on that demo page so that I could use it to get the value of editor.
Having said that, there normally should be some built-in method in that editor to get current value you should look at the docs :)