The next several exercises are timed. If you type slowly or dislike time pressure, feel free to increase the allotted time.
Name and email required. Check any number of boxes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
0
0
0
In the following code, if the selector is $("p:last-child"), how many elements will be selected? Answer with a numeral. | <div> <p>First paragraph</p> <p>Second paragraph</p> <p>Third paragraph</p> </div> <div> <p>First paragraph</p> <p>Second paragraph</p> </div> | 2 The third paragraph in the first div is its last child. The second paragraph in the second div is its last child. | ^ *2 *$ |
In the following code, if the selector is $("div:first-child"), how many divs will be selected? Answer with a numeral. | <body> <div> <div> <div> </div> </div> </div> </body> | 3 The selector specifies every div that's the first child of a parent. In the example, all three divs are the first--and also the last--child of a parent. The first div is the first child of the body. Each of the next two divs is the first child of the div that encloses it. | ^ *3 *$ |
If the selector is $("p:last-child"), what is the id of the selected element? Omit the quotation marks. | <div> <p id="paragraph_1"></p> <img id="pic_1" src="loris.jpg"> </div> <div> <img id="pic_2" src="porous.jpg"> <p id="paragraph_2"></p> </div> | paragraph_2 | ^ *paragraph_2 *$ |
If the selector is $("img:first-child"), what is the id of the selected element? Omit the quotation marks. | <div> <p id="paragraph_1"></p> <img id="pic_1" src="loris.jpg"> </div> <div> <img id="pic_2" src="porous.jpg"> <p id="paragraph_2"></p> </div> | pic_2 | ^ *pic_2 *$ |
5. Drag-and-drop: Holding down the left mouse button, drag the pieces of code onto the screen to arrange the divs and paragraphs so that only one paragraph will be selected by $("p:first-child"). Don't place any paragraphs outside a div. There are several possible correct codes. | If you placed all of the paragraphs inside one of the divs, you're correct. | ||
Select all paragraphs that are the first child of a parent. | $("p:first-child") | $`(`"`p`:`first`-`child`"`) | |
Select all divs that are the last child of a parent. | $("div:last-child") | ||
Select all headings of a certain size that are the first child of a parent. You choose the size. | $("h2:first-child") | ^ *\$\(•h[1-6]:first-child•\) *$ | |
Add a class to all divs that are the first child of a parent. Make up the class name. | $("div:first-child").addClass("important"); | ^ *\$\(•div:first-child•\)\.addClass\(•.+•\); *$ | |
Color all paragraphs that are the last child of a parent #cococo. | $("p:last-child").css("color", "#cococo"); | ^ *\$\(•p:last-child•\)\.css\(•color•, •#cococo•\); *$ | |
Select all list items that are the first child of a parent and assign a class to them. Make up the class name. | $("li:first-child").attr("class", "big"); | ^ *\$\(•li:first-child•\)\.attr\(•class•, •.+•\); *$ | |
In a single statement, select all images that are the first child of a parent and all paragraphs that are the last child of a parent. Remove all the selected elements. | $("img:first-child, p:last-child").remove(); | ^ *\$\(•img:first-child, p:last-child•\)\.remove\(\); *$ | |
Select all divs that are the last child of a parent. | $("div:last-child") | ^ *\$\(•div:last-child•\) *$ | |
Select all headings of a certain size that are the first child of a parent. You choose the size. | $("h2:first-child") | ^ *\$\(•h[1-6]:first-child•\) *$ | |
Add a class to all divs that are the first child of a parent. Make up the class name. | $("div:first-child").addClass("important"); | ^ *\$\(•div:first-child•\)\.addClass\(•.+•\); *$ | |
Color all paragraphs that are the last child of a parent #cococo. | $("p:last-child").css("color", "#cococo"); | ^ *\$\(•p:last-child•\)\.css\(•color•, •#cococo•\); *$ | |
Select all list items that are the first child of a parent and assign a class to them. Make up the class name. | $("li:first-child").attr("class", "big"); | ^ *\$\(•li:first-child•\)\.attr\(•class•, •.+•\); *$ | |
In a single statement, select all images that are the first child of a parent and all paragraphs that are the last child of a parent. Remove all the selected elements. | $("img:first-child, p:last-child").remove(); | ^ *\$\(•img:first-child, p:last-child•\)\.remove\(\); *$ | |
http://jsfiddle.net/ASmarterWayToLearn/0w90nzo3/ | |||
http://jsfiddle.net/ASmarterWayToLearn/5t7gvrjd/ |