1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
0,1,2,3,4,5,6,7,8,9
0
0
0
0
To target multiple elements, you use the ________() method. | querySelectorAll | querySelectorAll | |
The following code selects all _______ elements. (9 characters) | let allSomethings = document.querySelectorAll("p"); | paragraph | paragraph |
Fill in the blank to select all elements with the "normal" class. | let allThatShareClass = ______________; | document.querySelectorAll(".normal"); | document\.querySelectorAll\(•\.normal•\); |
Select all divs and assign them to the variable allDivs. | let allDivs = document.querySelectorAll("div"); | letallDivs=document\.querySelectorAll\(•div•\); | |
Select all ordered lists and unordered lists and assign them to a variable. Make up the variable name. | let allLists = document.querySelectorAll("ol, ul"); | let[a-z_$][a-zA-Z0-9_$]*=document\.querySelectorAll\(•ol,ul•\); | |
Select all th cells in a table and assign them to a variable. Make up the variable name. | let allHeadings = document.querySelectorAll("th"); | let[a-z_$][a-zA-Z0-9_$]*=document\.querySelectorAll\(•th•\); | |
All h2 headings have been selected and assigned to the variable h2s. Use a for loop to center them. | for (let i = 0; i < h2s.length; i++) { h2s[i].setAttribute("align", "center"); } |
for\(leti=0;i9Stumph2s\.length;i\+\+\){[\r\n]h2s\[i\]\.setAttribute\(•align•,•center•\);[\r\n]} | |
In a first statement, select all paragraphs and assign them to a variable. Then code a loop that inserts identical text into each paragraph. Make up the text. | let allGraphs = document.querySelectorAll("p"); for (let i = 0; i < allGraphs.length; i++) { allGraphs[i].textContent = "Text to come...."; } |
letallGraphs=document\.querySelectorAll\(•p•\);[\r\n]for\(leti=0;i9StumpallGraphs\.length;i\+\+\){[\r\n]allGraphs\[i\]\.textContent=•.*•;[\r\n]} | |
This one may take several tries. Don't blame yourself if you need to go back and review some chapters in the book. Keep at it. A bit of struggle embeds knowledge more deeply.
|
|||
Another challenging exercise. It tests you on several lessons in the book. Review chapters of the book as much as you need to.
|