---
title: "Element.selection() | Grafana k6 documentation"
description: "Retrieve the Selection matching this element."
---

# Element.selection()

Retrieve the Selection matching this element.

Mimics `$(element)`.

### Returns

Expand table

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

### Example

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```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())
	});
}
```
