JavaScript 6e – Test Review Questions
Chapter 5: Working with the Document Object Model (DOM) and DHTML
True / False
	
1. The top-level object in the browser object model is the Window object, which represents a web browser window.
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
292	

2. The objects in the BOM for any given web page depend on the contents of the page.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
293	

3. The getElementsBySelector() method​ returns a collection of elements matching a specified selector.
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
303	

4. Internet Explorer 8 does not support the textContent property.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
304	

5. A node attached with the appendChild() method is always added as the last child element of the parent element.​
 	
a. 	
True	

b. 	
False	

REFERENCES:  	
315	

Multiple Choice	

6. When you open a new web browser window, you can customize its appearance using the ____ argument of the window.open() method.
 	
a. 	
url	
b. 	
name	

c. 	
options	
d. 	
replace	

REFERENCES:  	
330	

7. In order to make a window the active window, you use the ____ method of the Window object.
 	
a. 	
open()	
b. 	
set()	

c. 	
focus()	
d. 	
active()	

REFERENCES:  	
334	

8. The ____ method is used in JavaScript to execute code after a specific amount of time has elapsed.
 	
a. 	
clearInterval()	
b. 	
clearTimeout()	

c. 	
setTimeout()	
d. 	
startTimeout()	

REFERENCES:  	
338	

9. The ____ method is used to cancel a setTimeout() method before its code executes.
 	
a. 	
stopTimeout()	
b. 	
cancelTimeout()	

c. 	
clearInterval()	
d. 	
clearTimeout()	

REFERENCES:  	
338	

10. The ____ method repeatedly executes the same code after being called only once.
 	
a. 	
setInterval()	
b. 	
loadInterval()	

c. 	
startInterval()	
d. 	
clearInterval()	

REFERENCES:  	
339	

11. The ____ method is used to clear a setInterval() method call.
 	
a. 	
exitInterval()	
b. 	
stopInterval()	

c. 	
clearInterval()	
d. 	
cancelInterval()	

REFERENCES:  	
339	

12. The History object contains a single property, the ____ property, which contains the specific number of documents that have been opened during the current browser session.
 	
a. 	
length	
b. 	
size	

c. 	
list	
d. 	
index	

REFERENCES:  	
342	

13. The ____ object allows you to change to a new web page from within JavaScript code.
 	
a. 	
Navigator	
b. 	
Browser	

c. 	
History	
d. 	
Location	

REFERENCES:  	
343	

14. The ____ object is used to obtain information about the current web browser.
 	
a. 	
Location	
b. 	
Navigator	

c. 	
History	
d. 	
Browser	

REFERENCES:  	
344	

15. Which method does NOT return a node list or HTML collection?​
 	
a. 	
​getElementById()	

b. 	
​getElementsByTagName()	

c. 	
​getElementsByClassName()	

d. 	
​getElementsByName()	

REFERENCES:  	
296
299	

16. Which method returns all h1 elements in a document?​
 	
a. 	
​getElementById("h1")	

b. 	
​getElementsByTagName("h1")	

c. 	
​getElementsByClassName("h1")	

d. 	
​getElementsByName("h1")	

REFERENCES:  	
299	

17. Which method returns all elements in a document that match the selector p figure img?​
 	
a. 	
​getElementsByTagName("p figure img")	

b. 	
​​getElementsByName("p figure img")	

c. 	
​querySelector("p figure img")	

d. 	
​querySelectorAll("p figure img")	

REFERENCES:  	
303	

18. Which is the correct way to reference the CSS font-family property in JavaScript when using dot notation?​
 	
a. 	
​font-family	
b. 	
​fontfamily	

c. 	
​fontFamily	
d. 	
​font.family	

REFERENCES:  	
305	

19. Which is the correct way to reference the href attribute of the element with the id value homeLink?​
 	
a. 	
​document.getElementById("homeLink").style.href	

b. 	
​document.getElementById("homeLink").attr.href	

c. 	
​document.getElementById("homeLink").attr("href")	

d. 	
​document.getElementById("homeLink").href	

REFERENCES:  	
306	

20. Which results in a node that exists independently of the DOM tree?​
 	
a. 	
​appendChild()	

b. 	
​createElement()	

c. 	
​insertBefore()	

d. 	
​setting the value of a variable referencing an independent node to null	

REFERENCES:  	
312	

21. Which method adds a node to a parent node before one or more existing child nodes?​
 	
a. 	
​appendChild()	
b. 	
​createElement()	

c. 	
​insertBefore()	
d. 	
​cloneNode()	

REFERENCES:  	
320	

22. The DOM hierarchy is also known as ____.
 	
a. 	
the API	
b. 	
the node	

c. 	
the ​DOM tree	
d. 	
​DHTML	

REFERENCES:  	
293	

23. Which method returns the element created by the HTML tag pair <p id="​weekend" class="first"></p>?
 	
a. 	
​getElementsByTagName("first")	

b. 	
​getElementById("first")	

c. 	
​querySelectorAll("first")	

d. 	
​getElementsByClassName("first")	

REFERENCES:  	
301	

24. Which method returns a single element?​
 	
a. 	
​getElementsByTagName()	
b. 	
​getElementsByClassName()	

c. 	
​querySelector()	
d. 	
​querySelectorAll()	

REFERENCES:  	
302	

25. A set of connected nodes that are not part of a document is known as a(n) ____.​
 	
a. 	
​node list	
b. 	
document fragment​	

c. 	
​HTML collection	
d. 	
​array	

REFERENCES:  	
312	

Completion	

26. The ____________________ object represents a web browser window.
REFERENCES:  	
292	

27. The Document object branch of the browser object model is represented by its own object model called the ______________________________.
REFERENCES:  	
293	

28. One way of referring to the Window object is by using the ____________________ property, which refers to the current Window object.
REFERENCES:  	
328	

29. For security reasons, you should use the ____________________ property when possible instead of the innerHTML property.​
REFERENCES:  	
304	

30. Each item in the DOM tree is known as a(n) ____________________.​
REFERENCES:  	
295	

Subjective Short Answer	
31. Explain the relationship between the Window object and the Document object.
REFERENCES:  	
292	

32. The first h2 element in a web page is created with the following tag pair: <h2 id="local" class="section"></h2>. Provide three different examples of code to reference this element using three different methods.
REFERENCES:  	
296, 297, 299, 300, 302, 303	

33. What is the difference between the content accessed by the textContent and innerHTML properties?
REFERENCES:  	
303, 304	

34. What is the difference in syntax between referencing a CSS property of an element and referencing an attribute of an element? Give an example of each.
REFERENCES:  	
305, 306	

35. Name two ways to add a node to the DOM, and explain when you'd use each.
REFERENCES:  	
312, 320, 321

	
36. How can you control a new window from the browser window that created it?
REFERENCES:  	
331, 332	

37. Describe the differences between the setTimeout() and setInterval() methods, and specify the method you use to cancel each.
REFERENCES:  	
337, 338	

38. Can you use JavaScript access URLs contained in the History object? If yes, provide code to do so. If no, why not?
REFERENCES:  	
342	

39. Is the Navigator object commonly used in determining which type of browser a user is running? Why or why not?
REFERENCES:  	
345, 346	

40. How can you center a web browser window in the middle of the display area?
REFERENCES:  	
347