Skip to content

Commit 2f47ae0

Browse files
Document element selection - grafana/k6#3519 (#1479)
Co-authored-by: Heitor Tashiro Sergent <[email protected]>
1 parent 7e1defb commit 2f47ae0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/sources/next/javascript-api/k6-html/element.md renamed to docs/sources/next/javascript-api/k6-html/element/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The Element object provides a similar API to the [DOM Element API](https://devel
1616

1717
| Method | Description |
1818
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
19+
| [selection](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-html/element/element-selection) | The selection matching the element. |
1920
| nodeName | The name of the element. |
2021
| nodeType | The type of the element. |
2122
| nodeValue | The element value. |
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: 'Element.selection()'
3+
description: 'Retrieve the Selection matching this element.'
4+
---
5+
6+
# Element.selection()
7+
8+
Retrieve the Selection matching this element.
9+
10+
Mimics `$(element)`.
11+
12+
### Returns
13+
14+
| Type | Description |
15+
| ------- | ------------------------------------ |
16+
| Selection | The Selection matching this element. |
17+
18+
### Example
19+
20+
{{< code >}}
21+
22+
```javascript
23+
import http from "k6/http";
24+
25+
export default () => {
26+
let li = http.get("https://test.k6.io").html().find("li");
27+
li.each(function(_, element) {
28+
let container = element.selection().closest('ul.header-icons');
29+
console.log("li.each", container.html())
30+
});
31+
}
32+
33+
```
34+
{{< /code >}}

0 commit comments

Comments
 (0)