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

[Term Entry] JavaScript DOM Manipulation: .querySelectorAll() #6296

Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b7d0b97
Creating new entry for querySelectorAll() method
DimitrovErik Mar 6, 2025
593b516
Creating new entry for querySelectorAll() method
DimitrovErik Mar 6, 2025
346ee8e
Update queryselectorall.md
DimitrovErik Mar 6, 2025
6ce327f
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
9549ccc
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
bafa054
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
39c08cc
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
b9ff516
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
0bfbefd
Adding explanation for 'selectors' parameter in queryselectorall.md
DimitrovErik Mar 7, 2025
772114d
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
cd258b8
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
ce891be
Update content/javascript/concepts/dom-manipulation/terms/queryselect…
DimitrovErik Mar 7, 2025
755f2a7
Deleting the Codebyte Example in queryselectorall.md
DimitrovErik Mar 7, 2025
9f43a77
minor fixes
mamtawardhani Mar 8, 2025
185da65
Fixing format:verify
DimitrovErik Mar 8, 2025
e8e79dc
Merge branch 'main' into javascript-dom-method-querySelectorAll
DimitrovErik Mar 9, 2025
a487511
Merge branch 'main' into javascript-dom-method-querySelectorAll
Sriparno08 Mar 12, 2025
8c84def
Minor changes
Sriparno08 Mar 12, 2025
46c6239
Rename queryselectorall.md to querySelectorAll.md
Sriparno08 Mar 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
Title: '.querySelectorAll()'
Description: 'Returns a static (not live) NodeList representing a list of the document`s elements that match the specified group of selectors.'
Subjects:
- 'Web Development'
- 'Developer Tools'
- 'Code Foundations'
Tags:
- 'Methods'
- 'Selectors'
- 'Node'
CatalogContent:
- 'introduction-to-javascript'
- 'paths/front-end-engineer-career-path'
---

# Document: querySelectorAll() method

The [Document](https://developer.mozilla.org/en-US/docs/Web/API/Document) method **querySelectorAll()** returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors.

## Syntax

```js
querySelectorAll(selectors);
```

## Example

To obtain a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) of all of the [< p >](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p) elements in the document:

```js
const matches = document.querySelectorAll("p");
```

This example returns a list of all [< div >](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div) elements within the document with a class of either note or alert:

```js
const matches = document.querySelectorAll("div.note, div.alert");
```

Here, we get a list of < p > elements whose immediate parent element is a < div > with the class highlighted and which are located inside a container whose ID is test.

```js
const container = document. querySelector("#test");
const matches = container.querySelectorAll("div.highlighted > p");
```


## Codebyte Example (if applicable)

We can currently support:

- JavaScript

We need to use different libraries or tools to parse and manipulate HTML content in ways similar to JavaScript's **.querySelectorAll()**:
- Python
- Ruby
- C++
- C#
- Go
- PHP

See [content-standards.md](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md) for more details!

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>querySelectorAll Example</title>
</head>
<body>
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>

<script>
// Select all <p> elements on the page
const paragraphs = document.querySelectorAll('p');

// Loop through each <p> element and add some extra text
paragraphs.forEach((para, index) => {
para.textContent += ` - Updated by querySelectorAll (${index + 1})`;
});
</script>
</body>
</html>

```