Range

A range of elements in a document. The user's selection is represented as a `Range`, among
other uses. Scripts can only access the selection of the user who is running the script, and only
if the script is [bound](https://developers.google.com/apps-script/scripts_containers) to the document.

```javascript
// Bold all selected text.
const selection = DocumentApp.getActiveDocument().getSelection();
if (selection) {
  const elements = selection.getRangeElements();
  for (let i = 0; i < elements.length; i++) {
    const element = elements[i];

    // Only modify elements that can be edited as text; skip images and other
    // non-text elements.
    if (element.getElement().editAsText) {
      const text = element.getElement().editAsText();

      // Bold the selected part of the element, or the full element if it's
      // completely selected.
      if (element.isPartial()) {
        text.setBold(
            element.getStartOffset(),
            element.getEndOffsetInclusive(),
            true,
        );
      } else {
        text.setBold(true);
      }
    }
  }
}
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/document/range#getRangeElements()` | `https://developers.google.com/apps-script/reference/document/range-element` | Gets all elements in this `Range`, including any partial `https://developers.google.com/apps-script/reference/document/text` elements (for example, in the case of a selection that includes only part of a `Text` element). |

### Deprecated methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/document/range#getSelectedElements()` | `https://developers.google.com/apps-script/reference/document/range-element` | Gets all elements that the user has selected in the open instance of the document, including any partially selected `https://developers.google.com/apps-script/reference/document/text` elements. |

## Detailed documentation

### `getRangeElements()`

Gets all elements in this `Range`, including any partial `https://developers.google.com/apps-script/reference/document/text` elements (for example, in the case
of a selection that includes only part of a `Text` element). To determine whether a
`Text` element is only partially included in the range, see `https://developers.google.com/apps-script/reference/document/range-element#isPartial()`.

#### Return


`https://developers.google.com/apps-script/reference/document/range-element` --- an array of elements, in the order they appear in the document

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

## Deprecated methods

### `getSelectedElements()`


**Deprecated.** Renamed to `https://developers.google.com/apps-script/reference/document/range#getRangeElements()`.

Gets all elements that the user has selected in the open instance of the document, including
any partially selected `https://developers.google.com/apps-script/reference/document/text`
elements.

#### Return


`https://developers.google.com/apps-script/reference/document/range-element` --- an array of selected or partially selected elements, in the order they appear in the
document

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`