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,31 @@
---
Title: 'setAttribute()'
Description: 'Sets the attribute of a specified element.'
Subjects:
- 'Web Development'
- 'Web Design'
- 'An nth subject name'
Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR!
- 'Attributes'
CatalogContent:
- 'introduction-to-javascript'
- 'paths/front-end-engineer-career-path'
---

The **`.setAttribute()`** method of the Element interface sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified 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

## Example

This example sets the name of a button to 'helloButton'.

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

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