@wordpress/dom Edit

DOM utilities module for WordPress.

Installation Installation

Install the module

npm install @wordpress/dom --save

Top ↑

API API

computeCaretRect computeCaretRect

Get the rectangle for the selection in a container.

Parameters

  • win Window: The window of the selection.

Returns

  • DOMRect | null: The rectangle.

Top ↑

documentHasSelection documentHasSelection

Check whether the current document has a selection. This checks for both
focus in an input field and general text selection.

Parameters

  • doc Document: The document to check.

Returns

  • boolean: True if there is selection, false if not.

Top ↑

documentHasTextSelection documentHasTextSelection

Check whether the current document has selected text. This applies to ranges
of text in the document, and not selection inside and