From 06f583ebc922471dcdaba1d30a278e695f69786f Mon Sep 17 00:00:00 2001 From: James <96701180+punkphloyd@users.noreply.github.com> Date: Wed, 5 Mar 2025 23:39:08 +0000 Subject: [PATCH 1/6] Initial commit, description and example of setAttribute() --- .../terms/setattribute/setattribute.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md diff --git a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md new file mode 100644 index 00000000000..ee9aa527634 --- /dev/null +++ b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md @@ -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); +``` + +## Example + +This example sets the name of a button to 'helloButton'. + +```js +const button = document.querySelector("button"); + +button.setAttribute("name","helloButton"); +``` \ No newline at end of file From 28fd3bfc3fca58716fce7643ba8461528caa5113 Mon Sep 17 00:00:00 2001 From: James <96701180+punkphloyd@users.noreply.github.com> Date: Wed, 12 Mar 2025 20:06:21 +0000 Subject: [PATCH 2/6] Update content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md Co-authored-by: Mamta Wardhani --- .../dom-manipulation/terms/setattribute/setattribute.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md index ee9aa527634..fb4b8460414 100644 --- a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md +++ b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md @@ -12,7 +12,7 @@ CatalogContent: - '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. +The **`.setAttribute()`** method of the Element interface sets or updates an attribute on the specified element. If the attribute exists, its value is updated; otherwise, a new attribute is added with the given name and value. ## Syntax From 93277a3054d35e81633ff6e7c9184b18140de9bd Mon Sep 17 00:00:00 2001 From: James <96701180+punkphloyd@users.noreply.github.com> Date: Wed, 12 Mar 2025 20:14:01 +0000 Subject: [PATCH 3/6] Add name/value definitions to example codeblock --- .../dom-manipulation/terms/setattribute/setattribute.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md index fb4b8460414..6c76561175c 100644 --- a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md +++ b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md @@ -17,7 +17,8 @@ The **`.setAttribute()`** method of the Element interface sets or updates an att ## Syntax ```pseudo -setAttribute(name, value); +// Sets the alignment of, e.g., a paragraph block to the right +setAttribute(name:"align", value:"right"); ``` ## Example @@ -28,4 +29,4 @@ This example sets the name of a button to 'helloButton'. const button = document.querySelector("button"); button.setAttribute("name","helloButton"); -``` \ No newline at end of file +``` From 155144ee938562a10cf176a8943cc1dff88b54f8 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Sun, 16 Mar 2025 10:38:15 +0530 Subject: [PATCH 4/6] minor fixes --- .../terms/setattribute/setattribute.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md index 6c76561175c..0e973ac3c6e 100644 --- a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md +++ b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md @@ -1,29 +1,31 @@ --- -Title: 'setAttribute()' +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! +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 exists, its value is updated; otherwise, a new attribute is added with the given name and value. +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 -// Sets the alignment of, e.g., a paragraph block to the right -setAttribute(name:"align", value:"right"); +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 of a button to 'helloButton'. +This example sets the `name` attribute of a button element to `"helloButton"`: ```js const button = document.querySelector("button"); From 506ff4cbf7b11da01790affbdc460e6a86df6e0a Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Tue, 18 Mar 2025 09:59:04 +0530 Subject: [PATCH 5/6] Minor changes --- .../terms/setattribute/setattribute.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md index 0e973ac3c6e..42286fde9c7 100644 --- a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md +++ b/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md @@ -1,34 +1,35 @@ --- -Title: '.setAttribute()' +Title: '.setAttribute()' Description: 'Sets the attribute of a specified element.' -Subjects: +Subjects: - 'Web Development' - 'Web Design' Tags: - 'Attributes' - 'DOM' -CatalogContent: +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. +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. ## Syntax ```pseudo -setAttribute(name, value); +elm.setAttribute(name, value); ``` +- `elm`: The element on which the `.setAttribute()` method is called. - `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"`: +This example sets the `"name"` attribute of a button element to `"helloButton"`: ```js -const button = document.querySelector("button"); +const button = document.querySelector('button'); -button.setAttribute("name","helloButton"); +button.setAttribute('name', 'helloButton'); ``` From 615ad458ee4a79373414d4105eaff359570508d8 Mon Sep 17 00:00:00 2001 From: Sriparno Roy <89148144+Sriparno08@users.noreply.github.com> Date: Tue, 18 Mar 2025 10:02:37 +0530 Subject: [PATCH 6/6] Rename setattribute.md to setAttribute.md --- .../setattribute.md => setAttribute/setAttribute.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/javascript/concepts/dom-manipulation/terms/{setattribute/setattribute.md => setAttribute/setAttribute.md} (100%) diff --git a/content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md b/content/javascript/concepts/dom-manipulation/terms/setAttribute/setAttribute.md similarity index 100% rename from content/javascript/concepts/dom-manipulation/terms/setattribute/setattribute.md rename to content/javascript/concepts/dom-manipulation/terms/setAttribute/setAttribute.md