Skip to content

Commit

Permalink
Document element selection - grafana/k6#3519 (#1479)
Browse files Browse the repository at this point in the history
Co-authored-by: Heitor Tashiro Sergent <heitortsergent@gmail.com>
  • Loading branch information
mstoykov and heitortsergent committed Jan 26, 2024
1 parent 7e1defb commit 2f47ae0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The Element object provides a similar API to the [DOM Element API](https://devel

| Method | Description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [selection](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-html/element/element-selection) | The selection matching the element. |
| nodeName | The name of the element. |
| nodeType | The type of the element. |
| nodeValue | The element value. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: 'Element.selection()'
description: 'Retrieve the Selection matching this element.'
---

# Element.selection()

Retrieve the Selection matching this element.

Mimics `$(element)`.

### Returns

| Type | Description |
| ------- | ------------------------------------ |
| Selection | The Selection matching this element. |

### Example

{{< code >}}

```javascript
import http from "k6/http";

export default () => {
let li = http.get("https://test.k6.io").html().find("li");
li.each(function(_, element) {
let container = element.selection().closest('ul.header-icons');
console.log("li.each", container.html())
});
}

```
{{< /code >}}

0 comments on commit 2f47ae0

Please sign in to comment.