---
title: "tinymce.dom.TreeWalker"
description: "TreeWalker class enables you to walk the DOM in a linear manner."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.dom.treewalker/"
md_url: "https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.dom.treewalker/index.md"
version: "6"
last_updated: "2022-07-13T05:38:26Z"
tokens: 427
---
Important This page documents TinyMCE 6. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../../latest/apis/tinymce.dom.treewalker/).
# tinymce.dom.TreeWalker

TreeWalker class enables you to walk the DOM in a linear manner.

## Examples

```javascript
const walker = new tinymce.dom.TreeWalker(startNode);

do {
  console.log(walker.current());
} while (walker.next());
```

## Summary

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [current()](#current) | Returns the current node. | `TreeWalker` |
| [next()](#next) | Walks to the next node in tree. | `TreeWalker` |
| [prev()](#prev) | Walks to the previous node in tree. | `TreeWalker` |

## Methods

### current()

```javascript
current(): Node | undefined
```
Returns the current node.

#### Return value

- `Node` - Current node where the walker is, or undefined if the walker has reached the end.
- `undefined` - Current node where the walker is, or undefined if the walker has reached the end.

### next()

```javascript
next(): Node | undefined
```
Walks to the next node in tree.

#### Return value

- `Node` - Current node where the walker is after moving to the next node, or undefined if the walker has reached the end.
- `undefined` - Current node where the walker is after moving to the next node, or undefined if the walker has reached the end.

### prev()

```javascript
prev(): Node | undefined
```
Walks to the previous node in tree.

#### Return value

- `Node` - Current node where the walker is after moving to the previous node, or undefined if the walker has reached the end.
- `undefined` - Current node where the walker is after moving to the previous node, or undefined if the walker has reached the end.
