From 6858070246f78fab77987037dc6fe4f621d8b79c Mon Sep 17 00:00:00 2001 From: Adedeji Agunbiade Date: Tue, 4 Mar 2025 18:10:20 +0100 Subject: [PATCH 1/5] Add description, syntax and examples for querySelectorAll() --- .../queryselectorall/queryselectorall.md | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md diff --git a/content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md b/content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md new file mode 100644 index 00000000000..24ad26f9dfd --- /dev/null +++ b/content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md @@ -0,0 +1,86 @@ +--- +Title: '.querySelectorAll()' +Description: 'Selects multiple elements from the DOM that matches a specific CSS selector.' +Subjects: + - 'Code Foundations' + - 'Computer Science' + - 'Web development' + - 'Web design' + +Tags: + - 'Web API' + - 'Conceptual' + - 'DOM' + - 'ES6' +CatalogContent: + - 'introduction-to-javascript' + - 'paths/computer-science' +--- + +The ``.querySelectorAll()`` method is a powerful tool in JavaScript for selecting multiple elements from the DOM that match a specified CSS selector. Unlike ``.querySelector()``, that returns only the first matching element, ``.querySelectorAll()`` returns a static NodeList containing all elements that match the given selector. + +This method is useful when you need to manipulate or interact with multiple elements at once, such as applying styles, adding event listeners, or updating content across several elements. + +## Syntax + + +```javascript +document.querySelectorAll(selector); +``` + +`selector` is a string containing one or more CSS selectors separated by commas. This can include any valid CSS selector, such as class names, IDs, element types, attributes, etc. + + +The `querySelectorAll` method returns a NodeList, which is a collection of nodes (elements) that match the specified selector(s). Note that a NodeList is not an array, but it can be iterated over using methods like forEach() or converted into an array using `Array.from()` +. +## Example + +Suppose you have the following HTML structure: + +```html + + + + Todolist + + + + + + +``` +You can use `.querySelectorAll()` to select all list items (`
  • `) with the class item and apply a style change to them: + + +```javascript +// Select all elements with the class "item" +const items = document.querySelectorAll('.item'); + +// Loop through the NodeList and apply a style change +items.forEach(item => { + item.style.color = 'blue'; +}); +``` + +In this example: + +`.querySelectorAll('.item')` selects all `
  • ` elements with the class item. + +The `forEach()` method is used to iterate over the NodeList and change the text color of each item to blue. + +You can also use more complex selectors. For instance, to select only the `
  • ` elements with both the item and completed classes: + +```javascript +const specialItem = document.querySelectorAll('.item.completed'); +specialItem.forEach(item => { + item.style.fontWeight = 'bold'; + item.style.textDecoration = 'underline'; +}); + +``` + \ No newline at end of file From d45c052d38c21e5f9669d2daa3865c2bec3508c9 Mon Sep 17 00:00:00 2001 From: Adedeji Agunbiade Date: Thu, 11 Dec 2025 09:12:35 +0100 Subject: [PATCH 2/5] chore: add cpp end term --- .../concepts/unordered-set/terms/end/end.md | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 content/cpp/concepts/unordered-set/terms/end/end.md diff --git a/content/cpp/concepts/unordered-set/terms/end/end.md b/content/cpp/concepts/unordered-set/terms/end/end.md new file mode 100644 index 00000000000..c6d74bd00f0 --- /dev/null +++ b/content/cpp/concepts/unordered-set/terms/end/end.md @@ -0,0 +1,108 @@ +Title: 'end()' +Description: 'Returns an iterator that points to the past-the-end position of the unordered set or the end position in a specific bucket.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'Iterators' + - 'Sets' + - 'STL' +CatalogContent: + - 'learn-c-plus-plus' + - 'paths/computer-science' +--- + +The **`end()`** method returns an iterator that points to the past-the-end position of an [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set). This iterator marks one past the last element and cannot be dereferenced. Because `unordered_set` does not maintain a defined order, iteration proceeds in the container’s internal hash-table order. + +## Syntax + +```pseudo +unordered_set_name.end(); +``` + +**Return value:** + +Returns an `iterator` pointing to the past-the-end position of the `unordered_set`. + +Or, to work with a specific bucket: + +```pseudo +unordered_set_name.end(n); +``` + +**Parameters:** + +- `n` (size_type): The bucket index. Must be less than `bucket_count()`. + +**Return value:** + +A `local_iterator` pointing to the past-the-end position in bucket `n`. If the bucket is empty, `begin(n) == end(n)`. + +## Example + +This example shows iterating over an `unordered_set` using `begin()` and `end()`: + +```cpp +#include +#include +using namespace std; + +int main() { + unordered_set unique_numbers = {10, 5, 20, 15}; + + for (auto it = unique_numbers.begin(); it != unique_numbers.end(); ++it) { + cout << *it << "\n"; + } + + return 0; +} +``` + +A sample output might be: + +```shell +20 +5 +10 +15 +``` + +> **Note:** The iterator returned by `end()` marks the boundary for iteration and cannot be dereferenced. + +## Codebyte Example + +This example retrieves iterators for a specific bucket in the `unordered_set` and prints all elements stored in that bucket: + +```codebyte/cpp +#include +#include +using namespace std; + +int main() { + unordered_set words = {"cat", "dog", "rabbit", "lion"}; + + size_t bucket = 0; + + auto it = words.begin(bucket); + auto last = words.end(bucket); + + cout << "Elements in bucket " << bucket << ":\n"; + + for (; it != last; ++it) { + cout << " " << *it << "\n"; + } + + return 0; +} +``` + +A sample output might be: + +```shell +Elements in bucket 0: + cat + dog + lion +``` + +Exact elements shown depend on the hash function and bucket count; your output may differ. From 1d5c61d3a19938ec8d1723cd32b277e150542ce8 Mon Sep 17 00:00:00 2001 From: Adedeji Agunbiade Date: Thu, 11 Dec 2025 09:56:22 +0100 Subject: [PATCH 3/5] Revert "Add description, syntax and examples for querySelectorAll()" This reverts commit 6858070246f78fab77987037dc6fe4f621d8b79c. --- .../queryselectorall/queryselectorall.md | 86 ------------------- 1 file changed, 86 deletions(-) delete mode 100644 content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md diff --git a/content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md b/content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md deleted file mode 100644 index 24ad26f9dfd..00000000000 --- a/content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md +++ /dev/null @@ -1,86 +0,0 @@ ---- -Title: '.querySelectorAll()' -Description: 'Selects multiple elements from the DOM that matches a specific CSS selector.' -Subjects: - - 'Code Foundations' - - 'Computer Science' - - 'Web development' - - 'Web design' - -Tags: - - 'Web API' - - 'Conceptual' - - 'DOM' - - 'ES6' -CatalogContent: - - 'introduction-to-javascript' - - 'paths/computer-science' ---- - -The ``.querySelectorAll()`` method is a powerful tool in JavaScript for selecting multiple elements from the DOM that match a specified CSS selector. Unlike ``.querySelector()``, that returns only the first matching element, ``.querySelectorAll()`` returns a static NodeList containing all elements that match the given selector. - -This method is useful when you need to manipulate or interact with multiple elements at once, such as applying styles, adding event listeners, or updating content across several elements. - -## Syntax - - -```javascript -document.querySelectorAll(selector); -``` - -`selector` is a string containing one or more CSS selectors separated by commas. This can include any valid CSS selector, such as class names, IDs, element types, attributes, etc. - - -The `querySelectorAll` method returns a NodeList, which is a collection of nodes (elements) that match the specified selector(s). Note that a NodeList is not an array, but it can be iterated over using methods like forEach() or converted into an array using `Array.from()` -. -## Example - -Suppose you have the following HTML structure: - -```html - - - - Todolist - - -
      -
    • Go to the gym
    • -
    • Read for two hours
    • -
    • Call Jerry
    • -
    • Take a nap
    • -
    - - - -``` -You can use `.querySelectorAll()` to select all list items (`
  • `) with the class item and apply a style change to them: - - -```javascript -// Select all elements with the class "item" -const items = document.querySelectorAll('.item'); - -// Loop through the NodeList and apply a style change -items.forEach(item => { - item.style.color = 'blue'; -}); -``` - -In this example: - -`.querySelectorAll('.item')` selects all `
  • ` elements with the class item. - -The `forEach()` method is used to iterate over the NodeList and change the text color of each item to blue. - -You can also use more complex selectors. For instance, to select only the `
  • ` elements with both the item and completed classes: - -```javascript -const specialItem = document.querySelectorAll('.item.completed'); -specialItem.forEach(item => { - item.style.fontWeight = 'bold'; - item.style.textDecoration = 'underline'; -}); - -``` - \ No newline at end of file From 022e83c90299ee99085c815a626d3e6d4ca7e152 Mon Sep 17 00:00:00 2001 From: Adedeji Agunbiade Date: Thu, 11 Dec 2025 10:02:57 +0100 Subject: [PATCH 4/5] Revert query selector update --- .../querySelectorAll/querySelectorAll.md | 56 ------------------- 1 file changed, 56 deletions(-) delete mode 100644 content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md diff --git a/content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md b/content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md deleted file mode 100644 index 9d1e2157596..00000000000 --- a/content/javascript/concepts/dom-manipulation/terms/querySelectorAll/querySelectorAll.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -Title: '.querySelectorAll()' -Description: 'Returns a static (non-live) NodeList of all elements in the document that match the given CSS selectors.' -Subjects: - - 'Code Foundations' - - 'Web Development' -Tags: - - 'Methods' - - 'Node' - - 'Selectors' -CatalogContent: - - 'introduction-to-javascript' - - 'paths/front-end-engineer-career-path' ---- - -In JavaScript, the **`.querySelectorAll()`** method under the `document` object returns a static (not live) `NodeList` of all elements that match the given group of [selectors](https://www.codecademy.com/resources/docs/css/selectors). - -## Syntax - -```pseudo -document.querySelectorAll(selectors); -``` - -- `selectors`: Represents a string containing one or more CSS selectors used to match elements in the document. It follows the same rules as CSS selectors and can include: - - Type selectors (`div`, `p`, `span`) - - Class selectors (`.class-name`) - - ID selectors (`#id-name`) - - Attribute selectors (`[type="text"]`, `[disabled]`) - - Combinations (`div p`, `.container > p`, `ul > li:first-child`) - -## Examples - -### Example 1 - -In this example, a `NodeList` of all `

    ` elements in the document is obtained: - -```js -const matches = document.querySelectorAll('p'); -``` - -### Example 2 - -The following example returns a list of all `

    ` elements in the document with a class of either `note` or `alert`: - -```js -const matches = document.querySelectorAll('div.note, div.alert'); -``` - -### Example 3 - -In this example, a list of `

    ` elements is obtained, whose immediate parent is a `

    ` with the class `highlighted`, and which are inside a container with the ID `test`: - -```js -const container = document.querySelector('#test'); -const matches = container.querySelectorAll('div.highlighted > p'); -``` From 22b81916e03130ff0161b08def742a525a96e92a Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 12 Dec 2025 17:54:03 +0530 Subject: [PATCH 5/5] Revise 'end()' documentation for clarity and details Updated the description of the 'end()' function for clarity and added parameters section. Modified example notes and removed sample output for bucket elements. --- .../concepts/unordered-set/terms/end/end.md | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/content/cpp/concepts/unordered-set/terms/end/end.md b/content/cpp/concepts/unordered-set/terms/end/end.md index c6d74bd00f0..5d2994a3b29 100644 --- a/content/cpp/concepts/unordered-set/terms/end/end.md +++ b/content/cpp/concepts/unordered-set/terms/end/end.md @@ -1,5 +1,6 @@ +--- Title: 'end()' -Description: 'Returns an iterator that points to the past-the-end position of the unordered set or the end position in a specific bucket.' +Description: 'Returns an iterator pointing just past the last element of the unordered set, marking the end of the container’s range.' Subjects: - 'Code Foundations' - 'Computer Science' @@ -20,6 +21,10 @@ The **`end()`** method returns an iterator that points to the past-the-end posit unordered_set_name.end(); ``` +**Parameters:** + +The `end()` function takes no parameters. + **Return value:** Returns an `iterator` pointing to the past-the-end position of the `unordered_set`. @@ -40,7 +45,7 @@ A `local_iterator` pointing to the past-the-end position in bucket `n`. If the b ## Example -This example shows iterating over an `unordered_set` using `begin()` and `end()`: +In this example, iteration runs from `begin()` to `end()` to print every element in the `unordered_set`: ```cpp #include @@ -67,7 +72,7 @@ A sample output might be: 15 ``` -> **Note:** The iterator returned by `end()` marks the boundary for iteration and cannot be dereferenced. +> **Note:** The output order may vary because `unordered_set` does not store elements in any defined sequence. ## Codebyte Example @@ -95,14 +100,3 @@ int main() { return 0; } ``` - -A sample output might be: - -```shell -Elements in bucket 0: - cat - dog - lion -``` - -Exact elements shown depend on the hash function and bucket count; your output may differ.