Quiz
JavaScript Dom and Events
This quiz has a time limit, so it opens in the usual player.
Questions in this quiz (60)
1Consider the following HTML and JS code. What is the value of pars.length?
<body>
<p> Paragraph 1 </p>
<div id="myDiv">
<p> Paragraph 2 </p>
</div>
</body>
var myDiv=document.getElementById("myDiv");
var pars=myDiv.getElementsByTagName("p");- A0
- B2
- C1
- D3
2Consider the following HTML and JS code. What is the value of pars.length?
<body>
<p> Paragraph 1 </p>
<div id="myDiv">
<p> Paragraph 2 </p>
</div>
</body>
var myDiv=document.getElementById("myDiv");
var pars=document.getElementsByTagName("p");- A0
- B1
- C3
- D2
3In the Prototype library, the $("p") function is equivalent to?
- Adocument.createElement("p");
- Bdocument.getElementsByTagName("p");
- Cdocument.getElementById("p");
- Ddocument.getElementByTagName("p");
4In JavaScript, does the DOM tree include the head section of the HTML page?
- AYes
- BNo
5Based on the following JS code which variable is local scoped?
var a=10;
function myFunc() {
var c=document.getElementById("myPar");
}- Adocument
- Ba
- Cc
- Dboth a and c
6var myP = document.getElementById("myP");
myP.children[1].style.backgroundColor = "silver";- ASets the background color to silver of the third child of element id="myP"
- BSets the background color to silver of the first child of element id="myP"
- CModifies all children of elemetn id="myP"
- DSets the second child of element id="myP" background to silver
- ESets the element id="myP" background to silver
7In Javascript, if you wanted to set a timer that calls function "myFunc" every second, which statement would you use?
- AsetInterval(1000, myFunc);
- BsetRepeat(myFunc, 1000);
- CsetInterval(myFunc, 1000);
- DsetTimeout(myFunc, 1000, REPEAT);
- EsetTimeout(myFunc, 1000);
8In JavaScript, what command can be used to remove a node from the DOM tree?
- Adocument.deleteChild(...)
- Bdocument.removeChild(...)
- Cdocument.killChild(...)
- Ddocument.unappendChild(...)
9Consider the following HTML code as a DOM tree:
<div id="myDiv>
<h1> Hello </h1>
<p> This is a test. </p>
<p> This is only <a myid="a" href=""> a test. </a> </p>
<p> There will be one more test. </p>
</div>
Is the element myid="a" a child of the div element?- Ayes
- Bno
10Consider the following HTML code as a DOM tree:
<div id="myDiv">
<h1> Hello </h1>
<p> This is a test. </p>
<p> This is only <a href=""> a test. </a> </p>
<p> There will be one more test. </p>
</div>
Is the h1 element an ancestor of the element <a>?- Ayes
- Bno
11Are the following two lines of code equivalent?
$("button").observe("click", myClick);
$("button").onclick = myClick;- Ano
- Byes
12What does the variable "this" refer to in the following JavaScript function:
function clickHandler() {
this.innerHTML = "clicked";
}- Ait refers to document.getElementsByTag("this").
- Bit refers to an HTML button element.
- Cit refers to the HTML element object that called this function.
- Dit refers to an HTML checkbox element.
13Consider the following HTML:
0: <div>
1: <h1> A </h1>
2: <p> B </p>
3: <p> C </p>
4: </div>
which statement would return the element at line 3?- A$("h1").children[0]
- BgetElementById("p")
- C$("div").children[2]
- D$("p")
14In JavaScript, which of the following provides the X coordinates with respect to the HTML element the mouse is over?
- Aevent.screenX
- Bevent.browserX
- Cevent.clientX
- Devent.offsetX
15Consider the following HTML form object:
<input type="text" id="name">
How do you access content the user typed into this text field?- A$("name").data
- B$("name").submit()
- C$("name").innerHTML
- D$("name").value
16Consider the following JavaScript code. What type is the variable p?
var p = document.getElementsByTagName("p");- Aa paragraph
- Ba DOM tree
- Can element object
- Dan array of element objects
17How would you create a new DOM node of type <p> in JavaScript?
- Adocument.createTextNode("<p>");
- B$("p").create();
- Cdocument.getElementById("p");
- Ddocument.createElement("p");
- Edocument.newParagraph(1);
18When does the global event "window.onload" get called?
- AAfter the webpage has been loaded.
- BOnly when the browser's refresh button is pressed.
- CAs soon as the JS file is linked to the HTML page.
- DWhen a new window is created by an alert().
19When interpreted as a DOM tree, how child nodes does div id="myDiv" have has children?
<p> Paragraph 1 </p>
<div id="myDiv">
<ul> <li> Item 1 </li>
<li> Item 2 </li>
<li> Item 3 </li>
</ul>
</div>
<p> Paragraph 2 </p>- A3
- B1
- C<ul>
- D4
20Consider the following HTML code as a DOM tree. How many children does the <body> element have?
<body>
<h1> My webpage </h1>
<div>
<p> Testing. </p>
<p> Another paragraph. </p>
</div>
</body>- A0
- B2
- C4
- D1
21Using the Prototype library, which of the following would be used to submit a form?
- Adocument.submit();
- B$("myForm").submitForm();
- C$("myForm").submit();
- D$("myForm").submit = true;
22Consider the following JS Prototype code. When will the function "myFunc" be called?
$("myPar").observe("mouseover", myFunc);
$("myPar").observe("keydown", myVar)- Aanytime an event occurs with element id="myPar"
- Banytime the mouse cursor moves within the element id="myPar"
- Cwhen a key is pressed down over element id="myPar"
- Dwhen the mouse cursor enters element id="myPar"
23Assume function myClick is already defined. Which line in the following JavaScript code contains an error?
0: var allPars = document.getElementsByTagName("p");
1: var myButton = document.getElementById("myButton");
2: myButton.onclick = myClick;
3: allPars.onclick = myClick;- A1
- B0
- CThere is no error in this code
- D3
24Consider the following JavaScript code. When will the function "myFunc" be called?
window.onload = function() {
setTimeout(myFunc, 1500);
}- AAfter 1500 seconds after the window.onload event
- BAfter 15 seconds after the window.onload event
- CAfter 3pm on the current day the webpage is being accessed.
- DAfter 1.5 seconds after the window.onload event
25Consider the following HTML code as a DOM tree:
<div id="myDiv>
<h1> Hello </h1>
<p> This is a test. </p>
<p> This is only <a href=""> a test. </a> </p>
<p> There will be one more test. </p>
</div>- A5
- B4
- C0
- D3
26Consider the following JavaScript code:
0: var allParas = document.getElementsByTagName("p");
1: for (var i = 0; i < allParas.length; i++) {
2: ???
3: }- AallParas[i].backgroundColor = "silver";
- BallParas[i].style.backgroundColor = "silver"
- CallParas.style.backgroundColor = "silver";
- DallParas.backgroundColor = "silver";
27What does the following JavaScript code snippet do?
$("button").stopObserving("mousemove");- Aremoves the event handler function for "mousemove" events for element with id="button"
- Bremoves the event handler function named "mousemove"
- Cremoves the event handler function named "mousemove" for element with id="button"
- Dstops the mouse from moving over any buttons
28Are the following two lines of code equivalent?
$("button").observe("click", myClick);
$("button").onclick = myClick;- Ano
- Byes
29In JavaScript, does the DOM tree include the head section of the HTML page?
- Ayes
- Bno
30In JavaScript, which of the following provides the X coordinates with respect to the HTML element the mouse is over?
- Aevent.offsetX
- Bevent.screenX
- Cevent.browserX
- Devent.clientX
31What does the following JavaScript code do?
var myP = document.getElementById("myP");
myP.children[1].style.backgroundColor = "silver";- ASets the element id="myP" background to silver
- BSets the background color to silver of the first child of element id="myP"
- CSets the background color to silver of the third child of element id="myP"
- DSets the second child of element id="myP" background to silver
- EModifies all children of elemetn id="myP"
32In the Prototype library, the $("p") function is equivalent to?
- Adocument.getElementsByTagName("p");
- Bdocument.getElementByTagName("p");
- Cdocument.getElementById("p");
- Ddocument.createElement("p");
33Consider the following HTML and JS code. What is the value of pars.length?
<body>
<p> Paragraph 1 </p>
<div id="myDiv">
<p> Paragraph 2 </p>
</div>
</body>
var myDiv=document.getElementById("myDiv");
var pars=myDiv.getElementsByTagName("p")- A2
- B3
- C0
- D1
34Consider the following HTML form object:
<input type="text" id="name">
How do you access content the user typed into this text field?- A$("name").data
- B$("name").submit()
- C$("name").value
- D$("name").innerHTML
35Consider the following HTML code as a DOM tree. How many children does the <body> element have?
<body>
<h1> My webpage </h1>
<div>
<p> Testing. </p>
<p> Another paragraph. </p>
</div>
</body>- A4
- B1
- C0
- D2
36When interpreted as a DOM tree, how child nodes does div id="myDiv" have has children?
<p> Paragraph 1 </p>
<div id="myDiv">
<ul> <li> Item 1 </li>
<li> Item 2 </li>
<li> Item 3 </li>
</ul>
</div>
<p> Paragraph 2 </p>- A1
- B4
- C<ul>
- D3
37What does the variable "this" refer to in the following JavaScript function:
function clickHandler() {
this.innerHTML = "clicked";
}- Ait refers to document.getElementsByTag("this").
- Bit refers to an HTML button element.
- Cit refers to the HTML element object that called this function
- Dit refers to an HTML checkbox element.
38Consider the following HTML:
0: <div>
1: <h1> A </h1>
2: <p> B </p>
3: <p> C </p>
4: </div>
which statement would return the element at line 3?- A$("div").children[2]
- BgetElementById("p")
- C$("h1").children[0]
- D$("p")
39Consider the following JavaScript code. What type is the variable p?
var p = document.getElementsByTagName("p")- Aan array of element objects
- Ban element object
- Ca paragraph
- Da DOM tree
40In Javascript, if you wanted to set a timer that calls function "myFunc" every second, which statement would you use?
- AsetInterval(myFunc, 1000);
- BsetTimeout(myFunc, 1000);
- CsetTimeout(myFunc, 1000, REPEAT);
- DsetRepeat(myFunc, 1000);
- EsetInterval(1000, myFunc);
41When does the global event "window.onload" get called?
- AAs soon as the JS file is linked to the HTML page.
- BAfter the webpage has been loaded.
- COnly when the browser's refresh button is pressed.
- DWhen a new window is created by an alert().
42Consider the following HTML and JS code. What is the value of pars.length?
<body>
<p> Paragraph 1 </p>
<div id="myDiv">
<p> Paragraph 2 </p>
</div>
</body>
var myDiv=document.getElementById("myDiv");
var pars=document.getElementsByTagName("p");- A2
- B0
- C3
- D1
43Consider the following HTML code as a DOM tree:
<div id="myDiv>
<h1> Hello </h1>
<p> This is a test. </p>
<p> This is only <a myid="a" href=""> a test. </a> </p>
<p> There will be one more test. </p>
</div>
Is the element myid="a" a child of the div element?- Ano
- Byes
44Assume function myClick is already defined. Which line in the following JavaScript code contains an error?
0: var allPars = document.getElementsByTagName("p");
1: var myButton = document.getElementById("myButton");
2: myButton.onclick = myClick;
3: allPars.onclick = myClick;- A1
- BThere is no error in this code
- C2
- D0
- E3
45Consider the following HTML code as a DOM tree:
<div id="myDiv>
<h1> Hello </h1>
<p> This is a test. </p>
<p> This is only <a href=""> a test. </a> </p>
<p> There will be one more test. </p>
</div>
How many descendant element nodes does the div have?- A3
- B4
- C5
- D0
46Consider the following HTML code as a DOM tree:
<div id="myDiv">
<h1> Hello </h1>
<p> This is a test. </p>
<p> This is only <a href=""> a test. </a> </p>
<p> There will be one more test. </p>
</div>
Is the h1 element an ancestor of the element <a>?- Ayes
- Bno
47What does the following JavaScript code snippet do?
$("button").stopObserving("mousemove");- Astops the mouse from moving over any buttons
- Bremoves the event handler function named "mousemove"
- Cremoves the event handler function for "mousemove" events for element with id="button"
- Dremoves the event handler function named "mousemove" for element with id="button"
48In JavaScript, what command can be used to remove a node from the DOM tree?
- Adocument.unappendChild(...)
- Bdocument.deleteChild(...)
- Cdocument.killChild(...)
- Ddocument.removeChild(...)
49Using the Prototype library, which of the following would be used to submit a form?
- A$("myForm").submit();
- B$("myForm").submitForm();
- Cdocument.submit();
- D$("myForm").submit = true;
50Consider the following JS Prototype code. When will the function "myFunc" be called?
$("myPar").observe("mouseover", myFunc);
$("myPar").observe("keydown", myVar)- Aanytime an event occurs with element id="myPar"
- Banytime the mouse cursor moves within the element id="myPar"
- Cwhen the mouse cursor enters element id="myPar"
- Dwhen a key is pressed down over element id="myPar"
51How would you create a new DOM node of type <p> in JavaScript?
- A$("p").create();
- Bdocument.createTextNode("<p>");
- Cdocument.newParagraph(1);
- Ddocument.getElementById("p");
- Edocument.createElement("p");
52Consider the following JavaScript code:
0: var allParas = document.getElementsByTagName("p");
1: for (var i = 0; i < allParas.length; i++) {
2: ???
3: }- AallParas.backgroundColor = "silver";
- BallParas[i].backgroundColor = "silver";
- CallParas[i].style.backgroundColor = "silver";
- DallParas.style.backgroundColor = "silver";
53Based on the following JS code which variable is local scoped?
var a=10;
function myFunc() {
var c=document.getElementById("myPar");
}- Ac
- Ba
- Cdocument
- Dboth a and c
54Consider the following JavaScript code. When will the function "myFunc" be called?
window.onload = function() {
setTimeout(myFunc, 1500);
}- AAfter 1500 seconds after the window.onload event
- BAfter 1.5 seconds after the window.onload event
- CAfter 3pm on the current day the webpage is being accessed.
- DAfter 15 seconds after the window.onload event
55Consider the following HTML code as a DOM tree. How many children does the <body> element have?
<body>
<h1> My webpage </h1>
<div>
<p> Testing. </p>
<p> Another paragraph. </p>
</div>
</body>
Select one:- A4
- B1
- C0
- D2
56Consider the following HTML and JS code. What is the value of pars.length?
<body>
<p> Paragraph 1 </p>
<div id="myDiv">
<p> Paragraph 2 </p>
</div>
</body>
var myDiv=document.getElementById("myDiv");
var pars=myDiv.getElementsByTagName("p");- A3
- B0
- C1
- D2
57What does the following JavaScript code do?
var myP = document.getElementById("myP");
myP.children[1].style.backgroundColor = "silver";- ASets the element id="myP" background to silver
- BSets the second child of element id="myP" background to silver
- CSets the background color to silver of the third child of element id="myP"
- DModifies all children of elemetn id="myP"
- ESets the background color to silver of the first child of element id="myP"
58What does the variable "this" refer to in the following JavaScript function:
function clickHandler() {
this.innerHTML = "clicked";
}- Ait refers to an HTML button element.
- Bit refers to document.getElementsByTag("this").
- Cit refers to an HTML checkbox element.
- Dit refers to the HTML element object that called this function
59Consider the following HTML:
0: <div>
1: <h1> A </h1>
2: <p> B </p>
3: <p> C </p>
4: </div>
which statement would return the element at line 3?- A$("h1").children[0]
- B$("p")
- C$("div").children[2]
- DgetElementById("p")
60When interpreted as a DOM tree, how child nodes does div id="myDiv" have has children?
<p> Paragraph 1 </p>
<div id="myDiv">
<ul> <li> Item 1 </li>
<li> Item 2 </li>
<li> Item 3 </li>
</ul>
</div>
<p> Paragraph 2 </p>- A<ul>
- B3
- C4
- D1
Information
- Description
- EECS 1012- Quiz on JavaScript Dom and Events, created by Junaid Khan on 03/12/2017.
- Author
- Junaid Khan
- Language
- English
- Views
- 1
- History
- Created on 3 Dec 2017 · updated on 4 Dec 2017
- Tags
- Rating
- No ratings yet Rate this quiz