diff --git a/docs/sources/next/javascript-api/k6-html/element.md b/docs/sources/next/javascript-api/k6-html/element/_index.md similarity index 97% rename from docs/sources/next/javascript-api/k6-html/element.md rename to docs/sources/next/javascript-api/k6-html/element/_index.md index cc72cfdfd1..54e8d98622 100644 --- a/docs/sources/next/javascript-api/k6-html/element.md +++ b/docs/sources/next/javascript-api/k6-html/element/_index.md @@ -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//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. | diff --git a/docs/sources/next/javascript-api/k6-html/element/element-selection.md b/docs/sources/next/javascript-api/k6-html/element/element-selection.md new file mode 100644 index 0000000000..c029123e1d --- /dev/null +++ b/docs/sources/next/javascript-api/k6-html/element/element-selection.md @@ -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 >}}