Examples

Get and Set HTML of RichTextEditor

  • To retrieve the editor HTML, call the editor.getHTMLCode method of the editor instance.
  • The editor.setHTMLCode method can be used to set the Html when the editor is first displayed.
  • The editor.getText method can be used to retrieve the string contents of the editor.

Demo Code:

<link rel="stylesheet" href="/richtexteditor/rte_theme_default.css" />
<script type="text/javascript" src="/richtexteditor/rte.js"></script>
<script type="text/javascript" src='/richtexteditor/plugins/all_plugins.js'></script>

<div id="div_editor1"></div>

<script>
	var editor1 = new RichTextEditor("#div_editor1");

	editor1.setHTMLCode("<p><b>Hello</b> World</p><p>Click the button below to show this HTML code</p>");

	function btngetHTMLCode() {
		alert(editor1.getHTMLCode())
	}

	function btnsetHTMLCode() {
		editor1.setHTMLCode("<h1>editor1.setHTMLCode() sample</h1><p>You clicked the setHTMLCode button at " + new Date() + "</p>")
	}
	function btngetPlainText() {
		alert(editor1.getPlainText())
	}

</script>
<div class="content-space-1">
	<button class="btn btn-sm btn-outline-primary btn-pill transition-3d-hover px-5" onclick="btngetHTMLCode();return false;">Get Html Code</button>
	<button class="btn btn-sm btn-primary btn-pill transition-3d-hover px-5" onclick="btnsetHTMLCode();return false;">Set Html Code</button>
	<button class="btn btn-sm btn-outline-info btn-pill transition-3d-hover px-5" onclick="btngetPlainText();return false;">Get Plain Text</button>
</div>