---
title: "TreeWalker | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Interface TreeWalker

The **`TreeWalker`** object represents the nodes of a document subtree and a position within them.

[MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker)

interface TreeWalker {  
    [currentNode](#currentnode): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/);  
    [filter](#filter): [NodeFilter](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.NodeFilter/) | null;  
    [root](#root): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/);  
    [whatToShow](#whattoshow): number;  
    [firstChild](#firstchild-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
    [lastChild](#lastchild-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
    [nextNode](#nextnode-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
    [nextSibling](#nextsibling-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
    [parentNode](#parentnode-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
    [previousNode](#previousnode-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
    [previousSibling](#previoussibling-1)(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null;  
}

##### Index

### Properties[](#properties)

[currentNode](#currentnode) [filter](#filter) [root](#root) [whatToShow](#whattoshow)

### Methods[](#methods)

[firstChild](#firstchild) [lastChild](#lastchild) [nextNode](#nextnode) [nextSibling](#nextsibling) [parentNode](#parentnode) [previousNode](#previousnode) [previousSibling](#previoussibling)

## Properties[](#properties-1)

### currentNode[](#currentnode)

currentNode: [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/)

The **`TreeWalker.currentNode`** property represents the Node which the TreeWalker is currently pointing at.

[MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/currentNode)

### `Readonly`filter[](#filter)

filter: [NodeFilter](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.NodeFilter/) | null

The **`TreeWalker.filter`** read-only property returns the NodeFilter associated with the TreeWalker.

[MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/filter)

### `Readonly`root[](#root)

root: [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/)

The **`TreeWalker.root`** read-only property returns the root Node that the TreeWalker traverses.

[MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/root)

### `Readonly`whatToShow[](#whattoshow)

whatToShow: number

The **`TreeWalker.whatToShow`** read-only property returns a bitmask that indicates the types of nodes to show. Non-matching nodes are skipped, but their children may be included, if relevant.

[MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/whatToShow)

## Methods[](#methods-1)

### firstChild[](#firstchild)

-   firstChild(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#firstchild-1)
    
    The **`TreeWalker.firstChild()`** method moves the current Node to the first visible child of the current node, and returns the found child. If no such child exists, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/firstChild)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
    

### lastChild[](#lastchild)

-   lastChild(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#lastchild-1)
    
    The **`TreeWalker.lastChild()`** method moves the current Node to the last visible child of the current node, and returns the found child. If no such child exists, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/lastChild)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
    

### nextNode[](#nextnode)

-   nextNode(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#nextnode-1)
    
    The **`TreeWalker.nextNode()`** method moves the current Node to the next visible node in the document order, and returns the found node. If no such node exists, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/nextNode)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
    

### nextSibling[](#nextsibling)

-   nextSibling(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#nextsibling-1)
    
    The **`TreeWalker.nextSibling()`** method moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/nextSibling)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
    

### parentNode[](#parentnode)

-   parentNode(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#parentnode-1)
    
    The **`TreeWalker.parentNode()`** method moves the current Node to the first visible ancestor node in the document order, and returns the found node. If no such node exists, or if it is above the TreeWalker's root node, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/parentNode)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
    

### previousNode[](#previousnode)

-   previousNode(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#previousnode-1)
    
    The **`TreeWalker.previousNode()`** method moves the current Node to the previous visible node in the document order, and returns the found node. If no such node exists, or if it is before that the root node defined at the object construction, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/previousNode)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
    

### previousSibling[](#previoussibling)

-   previousSibling(): [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null[](#previoussibling-1)
    
    The **`TreeWalker.previousSibling()`** method moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, it returns null and the current node is not changed.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/TreeWalker/previousSibling)
    
    #### Returns [Node](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Node/) | null
