Tab

A tab within a Google Docs document.

```javascript
// Get all of the first-level tabs (tabs that are not nested within a parent
// tab) in the document.
// TODO(developer): Replace the ID with your own.
const tabs = DocumentApp.openById('123abc').getTabs();

// Get a specific tab based on the tab ID.
// TODO(developer): Replace the IDs with your own.
const tab = DocumentApp.openById('123abc').getTab('123abc');
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/document/tab#asDocumentTab()` | `https://developers.google.com/apps-script/reference/document/document-tab` | Retrieves the tab contents as a `https://developers.google.com/apps-script/reference/document/document-tab`. |
| `https://developers.google.com/apps-script/reference/document/tab#getChildTabs()` | `https://developers.google.com/apps-script/reference/document/tab#` | Retrieves the child tabs nested within this tab. |
| `https://developers.google.com/apps-script/reference/document/tab#getId()` | `String` | Retrieves the ID of the tab. |
| `https://developers.google.com/apps-script/reference/document/tab#getIndex()` | `Integer` | Retrieves the 0-based index of the tab within the parent. |
| `https://developers.google.com/apps-script/reference/document/tab#getTitle()` | `String` | Retrieves the title of the tab. |
| `https://developers.google.com/apps-script/reference/document/tab#getType()` | `https://developers.google.com/apps-script/reference/document/tab-type` | Retrieves the type of tab. |

## Detailed documentation

### `asDocumentTab()`

Retrieves the tab contents as a `https://developers.google.com/apps-script/reference/document/document-tab`.

#### Return


`https://developers.google.com/apps-script/reference/document/document-tab` --- The tab as a `https://developers.google.com/apps-script/reference/document/document-tab`.

*** ** * ** ***

### `getChildTabs()`

Retrieves the child tabs nested within this tab.

#### Return


`https://developers.google.com/apps-script/reference/document/tab#` --- The child tabs nested within this tab.

#### 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`

*** ** * ** ***

### `getId()`

Retrieves the ID of the tab.

#### Return


`String` --- The ID of the tab.

#### 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`

*** ** * ** ***

### `getIndex()`

Retrieves the 0-based index of the tab within the parent.

#### Return


`Integer` --- The index of the tab within the parent.

#### 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`

*** ** * ** ***

### `getTitle()`

Retrieves the title of the tab.

#### Return


`String` --- The title of the tab.

#### 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`

*** ** * ** ***

### `getType()`

Retrieves the type of tab.

Use this method to determine the content type of this `https://developers.google.com/apps-script/reference/document/tab#` before casting to the more
specific type using `https://developers.google.com/apps-script/reference/document/tab#asDocumentTab()`.

```javascript
const tab = DocumentApp.getActiveDocument().getActiveTab();
// Use getType() to determine the tab's type before casting.
if (tab.getType() === DocumentApp.TabType.DOCUMENT_TAB) {
  // It's a document tab, write some text to it.
  tab.asDocumentTab().setText('Hello World!');
} else {
  // There are currently no types other than DOCUMENT_TAB.
}
```

#### Return


`https://developers.google.com/apps-script/reference/document/tab-type` --- The tab's type.

#### 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`