-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Sriparno08
merged 11 commits into
Codecademy:main
from
punkphloyd:javascript-dom-setattribute
Mar 18, 2025
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
06f583e
Initial commit, description and example of setAttribute()
punkphloyd 28fd3bf
Update content/javascript/concepts/dom-manipulation/terms/setattribut…
punkphloyd 93277a3
Add name/value definitions to example codeblock
punkphloyd 155144e
minor fixes
mamtawardhani 891c404
Merge branch 'main' into javascript-dom-setattribute
mamtawardhani 0b88ff6
Merge branch 'main' into javascript-dom-setattribute
Sriparno08 f3b3e3e
Merge branch 'main' of https://github.com/Codecademy/docs into javasc…
Sriparno08 506ff4c
Minor changes
Sriparno08 d35410a
Merge branch 'javascript-dom-setattribute' of https://github.com/punk…
Sriparno08 615ad45
Rename setattribute.md to setAttribute.md
Sriparno08 d9d792e
Merge branch 'main' into javascript-dom-setattribute
Sriparno08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` | ||
|
||
- `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"); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
:There was a problem hiding this comment.
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
There was a problem hiding this comment.
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