Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document element selection - grafana/k6#3519 #1479

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 that is matching the element |
mstoykov marked this conversation as resolved.
Show resolved Hide resolved
| 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()'
excerpt: 'Retrieve the Selection matching this element.'
mstoykov marked this conversation as resolved.
Show resolved Hide resolved
---

# Element.selection()

Retrieve the Selection matching this element.

Mimics `$(element)`
mstoykov marked this conversation as resolved.
Show resolved Hide resolved

### Returns

| Type | Description |
| ------- | ------------------------------------ |
| Selection | The Selection mathing this element. |
mstoykov marked this conversation as resolved.
Show resolved Hide resolved

### 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 >}}
Loading