-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
54 lines (38 loc) · 999 Bytes
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "TreeWalker: lastChild() method"
short-title: lastChild()
slug: Web/API/TreeWalker/lastChild
page-type: web-api-instance-method
browser-compat: api.TreeWalker.lastChild
---
{{ APIRef("DOM") }}
The **`TreeWalker.lastChild()`** method moves the current
{{domxref("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.
## Syntax
```js-nolint
lastChild()
```
### Parameters
None.
### Return value
A {{domxref("Node")}} object or `null`.
## Examples
```js
const treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT,
{
acceptNode(node) {
return NodeFilter.FILTER_ACCEPT;
},
},
);
const node = treeWalker.lastChild(); // returns the last visible child of the root element
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{domxref("TreeWalker")}} interface it belongs to.