---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---

# setAttribute

The `setAttribute` method sets the value of the specified attribute on the element. If the value already exists, it will be updated; otherwise, a new attribute with the specified name and value will be added to the element.

## Syntax

```js
element.setAttribute(attributeName, value);
```

### Parameters

- `attributeName` _: string_
  - The name of the attribute to set.
- `value` _: string_
  - The value to assign to the attribute.

