editor.setImageForCommand
Adds an image (svg or png) for cmdname to the element. For details, please refer to plugin example.
Syntax
editor.setImageForCommand(element,cmdname)
Parameters
Type: HTMLElement
The specified HTML Element.
Parameters
Type: String
The name of a command.
Example usage
Code example
var editor1 = new RichTextEditor("#div_editor1");
var btn=document.createElement("span");
btn.style.cssText="width:32px;height:32px;display:inline-block;border:solid 1px darkgreen";
editor1.container.parentNode.insertBefore(btn,editor1.container);
editor1.setImageForCommand(btn,"bold"); Calling editor.setImageForCommand() from your app
editor.setImageForCommand() 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
Code example
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.setImageForCommand(...);React and Next.js
Code example
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);
function onClick() {
editorRef.current?.setImageForCommand(...);
}
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.