Skip to content

Commit 9f43a77

Browse files
minor fixes
1 parent 755f2a7 commit 9f43a77

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

content/javascript/concepts/dom-manipulation/terms/queryselectorall/queryselectorall.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
Title: '.querySelectorAll()'
33
Description: 'Returns a static (non-live) NodeList of all elements in the document that match the specified CSS selectors.'
4-
54
Subjects:
65
- 'Code Foundations'
76
- 'Developer Tools'
@@ -15,32 +14,41 @@ CatalogContent:
1514
- 'paths/front-end-engineer-career-path'
1615
---
1716

18-
# Document: querySelectorAll() method
19-
2017
The document method **`querySelectorAll()`** returns a static (not live) `NodeList` of all elements that match the specified group of selectors.
2118

2219
## Syntax
2320

2421
```pseudo
2522
querySelectorAll(selectors);
2623
```
27-
- **`selectors`**:
28-
This is a string representing one or more CSS selectors used to identify the elements you want to select from the document. You can use any valid CSS selector, including element selectors (e.g., `div`, `p`), class selectors (e.g., `.class-name`), id selectors (e.g., `#id-name`), and complex selectors (e.g., `div > p.class-name`). If multiple selectors are provided, they should be separated by commas (e.g., `'.class-name, #id-name'`).
2924

30-
## Example
25+
- `selectors`: A string containing one or more CSS selectors used to match elements in the document. It follows the same rules as CSS [selectors](https://www.codecademy.com/resources/docs/css/selectors) and can include:
26+
- Type selectors (`div`, `p`, `span`)
27+
- Class selectors (`.class-name`)
28+
- ID selectors (`#id-name`)
29+
- Attribute selectors (`[type="text"]`, `[disabled]`)
30+
- Combinations (`div p`, `.container > p`, `ul > li:first-child`)
31+
32+
## Examples
33+
34+
### Example 1
3135

3236
In this example, a `NodeList` of all `<p>` elements in the document is obtained:
3337

3438
```js
3539
const matches = document.querySelectorAll("p");
3640
```
3741

42+
### Example 2
43+
3844
This example returns a list of all `<div>` elements in the document with a class of either `note` or `alert`:
3945

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

50+
### Example 3
51+
4452
In this example, we get a list of `<p>` elements whose immediate parent is a `<div>` with the class `highlighted`, and which are inside a container with the ID `test`:
4553

4654
```js

0 commit comments

Comments
 (0)