---
title: "Selection.attr(name) | Grafana k6 documentation"
description: "Get the value of an attribute for the first element in the Selection."
---

# Selection.attr(name)

Get the value of an attribute for the first element in the Selection. Mimics [jquery.attr](https://api.jquery.com/attr/)

Expand table

| Parameter | Type   | Description                      |
|-----------|--------|----------------------------------|
| name      | string | The name of the attribute to get |

### Returns

Expand table

| Type   | Description                |
|--------|----------------------------|
| string | The value of the attribute |

### Example

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

```javascript
import { parseHTML } from 'k6/html';
import http from 'k6/http';

export default function () {
  const res = http.get('https://k6.io');
  const doc = parseHTML(res.body);
  const langAttr = doc.find('html').attr('lang');
}
```
