Documentation

editor.getSelectedControl()

Returns the control element that is currently selected — typically an image the user has clicked, shown with resize handles. It returns null when the selection is ordinary text or a caret. Use it to build context actions for a selected object, such as an “edit image” or “set alt text” button.

Syntax

editor.getSelectedControl()

Parameters

None.

Returns

The selected control element, or null if no control is selected.

Behavior notes

  • Control selection is distinct from text selection. Clicking an image selects it as a control; dragging across words is a text range. Only the former makes getSelectedControl() return an element.
  • Returns null for a caret or text range. Guard for null before touching the result.
  • It drives object-specific behavior. The editor itself checks the selected control in operations like delete(), which removes the selected image rather than text.

Example usage

Only enable an “edit image” action when an image is selected:

var editor1 = new RichTextEditor("#div_editor1");
var control = editor1.getSelectedControl();
if (control && control.tagName === "IMG") {
    openImageOptions(control);   // e.g. resize, alt text, replace
}

Read the source URL of the currently selected image:

var control = editor1.getSelectedControl();
var src = control && control.tagName === "IMG" ? control.src : null;

Related