-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQueryQuiz2.txt
85 lines (57 loc) · 1.97 KB
/
jQueryQuiz2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
jQuery Quiz II
------------------------------------------------------------------------------------------------------
1. Which, if any, of the following 3 code fragments are equivalent? Explain why they are different, if
they are. Explain why they can have different parameters and be equivalent, if they are equivalent.
//code fragment 1
$("li").each(function(idx, e) {
$(e).css(“color”, “yellow”); });
//code fragment 2
$("li").each(function() {
$(this).css(“color”, “yellow”); });
//code fragment 3
$("li").each(function(idx) {
$(this).css(“color”, “yellow”); });
Answer:
********
Here, code fragment 2 and code fragment 3 are equivalent. Both function apply css of color yellow
on current object using this reference. Even their parameters are different, the concept of
Rest parameters says you can have variable number of agruments in the function and use which you need.
------------------------------------------------------------------------------------------------------
2. Write a jQuery expression to find all divs on a page that include an unordered list in them, and make
their text color be blue.
<div>no ul here </div>
<div>
This does contain a ul.
<ul>
<li>the first item</li>
<li>the second item</li>
</ul>
</div>
<script>
<!—INSERT YOUR JQUERY CODE HERE - - >
</script>
</body>
Answer:
********
$(function() {
$('div > ul').css('color','blue');
});
------------------------------------------------------------------------------------------------------
3. Write jQuery code to append the following div element (and all of its contents) dynamically to the body
element.
<div><h1>JQuery Core</h1></div>
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
Answer:
********
$(function() {
$('<div><h1>JQuery Core</h1></div>').appendTo('body');
});