Skip to content

Commit 3c3d351

Browse files
authored
[Term Entry] JavaScript DOM Manipulation: .setAttribute()
* Initial commit, description and example of setAttribute() * Update content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md Co-authored-by: Mamta Wardhani <[email protected]> * Add name/value definitions to example codeblock * minor fixes * Minor changes * Rename setattribute.md to setAttribute.md ---------
1 parent 6e99475 commit 3c3d351

File tree

1 file changed

+35
-0
lines changed
  • content/javascript/concepts/dom-manipulation/terms/setAttribute

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
Title: '.setAttribute()'
3+
Description: 'Sets the attribute of a specified element.'
4+
Subjects:
5+
- 'Web Development'
6+
- 'Web Design'
7+
Tags:
8+
- 'Attributes'
9+
- 'DOM'
10+
CatalogContent:
11+
- 'introduction-to-javascript'
12+
- 'paths/front-end-engineer-career-path'
13+
---
14+
15+
The **`.setAttribute()`** method of the `Element` interface sets or updates an attribute of the specified element. If the given attribute already exists, its value is updated; otherwise, a new attribute is created with the given name and value.
16+
17+
## Syntax
18+
19+
```pseudo
20+
elm.setAttribute(name, value);
21+
```
22+
23+
- `elm`: The element on which the `.setAttribute()` method is called.
24+
- `name` (string): The name of the attribute to set (e.g., `"class"`, `"id"`, `"href"`).
25+
- `value` (string): The value to assign to the specified attribute.
26+
27+
## Example
28+
29+
This example sets the `"name"` attribute of a button element to `"helloButton"`:
30+
31+
```js
32+
const button = document.querySelector('button');
33+
34+
button.setAttribute('name', 'helloButton');
35+
```

0 commit comments

Comments
 (0)