Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit, description and example of setAttribute() #6280

Merged
merged 11 commits into from
Mar 18, 2025
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
Title: '.setAttribute()'
Description: 'Sets the attribute of a specified element.'
Subjects:
- 'Web Development'
- 'Web Design'
Tags:
- 'Attributes'
- 'DOM'
CatalogContent:
- 'introduction-to-javascript'
- 'paths/front-end-engineer-career-path'
---

The **`.setAttribute()`** method of the Element interface sets or updates an attribute on the specified element. If the attribute already exists, its value is updated; otherwise, a new attribute is created with the given name and value.

## Syntax

```pseudo
setAttribute(name, value);
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define the parameters here in the format:

  • name:
  • value:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this and pushed it from my local clone to my remote github repo.
I can't see how to incorporate it into a pull request without generating a new one - apologies! Could you please advise?
Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @punkphloyd you will have to be on the sam branch and commit and push the changes, that way it will get pushed in this PR itself

- `name` (string): The name of the attribute to set (e.g., `"class"`, `"id"`, `"href"`).
- `value` (string): The value to assign to the specified attribute.

## Example

This example sets the `name` attribute of a button element to `"helloButton"`:

```js
const button = document.querySelector("button");

button.setAttribute("name","helloButton");
```
Loading