editor.insertRootParagraph(tagname)
This method is used for inserting a new paragraph at the bottom of editor.
Syntax
editor.insertRootParagraph(tagname)
Parameter
Type: String
Optional. The tag name (div, br, p). If not specified, the tag defined by config.enterKeyTag will be inserted.
Return Value
Type: HTMLElement
The HtmlElement that was just inserted. If insertion failed, this will return null.
Example usage
var editor1 = new RichTextEditor("#div_editor1");
for(var i=1;i<10;i++)
{
editor1.selectDoc(false);
var p=editor1.insertRootParagraph("P");
p.innerText="paragraph "+i;
} Calling editor.insertRootParagraph() from your app
editor.insertRootParagraph() belongs to the editor instance. Every integration below works the same way: keep the object that new RichTextEditor(...) returns, and call it on that object.
Plain JavaScript
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.insertRootParagraph(tagname);React and Next.js
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);
function onClick() {
editorRef.current?.insertRootParagraph(tagname);
}
return <RichTextEditor editorRef={editorRef} />;In Vue and Angular, the wrapper components in the guides keep the instance in a component variable (editor), so the call is the same. See the React, Vue and Angular pages, or download a tested project from the guides.
If the editor is undefined
- The call ran before the component mounted. Call it from an event handler or after the mount effect has run.
- In React development mode, Strict Mode mounts, unmounts and mounts again, so the wrapper sets
editorRef.currenttonullin between. UseeditorRef.current?.rather than storing the instance elsewhere. - The editor was destroyed (
editor.destroy()) when its component unmounted.
All methods: method reference · all events: event reference.