JavaScript Questions & Answers – HTML DOM

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “HTML DOM”.

1. What is the reason for avoiding the attributes property in the HTML DOM?
a) Found unnecessary
b) Attributes don’t have attributes
c) Attributes have attributes
d) Considered irrelevant
View Answer

Answer: b
Explanation: When a web page is loaded, the browser creates a Document Object Model of the page. The reason for avoiding the attributes property in the HTML DOM is because Attributes don’t have attributes.
advertisement

2. What is the purpose of the method nodeMap.setNamedItem()?
a) Sets ID
b) Sets attribute node
c) Sets element name
d) Sets element type
View Answer

Answer: b
Explanation: The setNamedItem() method adds the specified node to the NamedNodeMap. The method nodeMap.setNamedItem() sets the specified attribute node (by name).

3. How is everything treated in HTML DOM?
a) Node
b) Attributes
c) Elements
d) Arrays
View Answer

Answer: a
Explanation: The HTML DOM model is constructed as a tree of Objects. In the HTML DOM (Document Object Model), everything is a node:

  • The document itself is a document node.
  • All HTML elements are element nodes.
  • All HTML attributes are attribute nodes.
  • Text inside HTML elements are text nodes.
  • Comments are comment nodes.
advertisement
advertisement

4. What does the NamedNodeMap object represent in the HTML DOM?
a) Unordered collection of elements
b) Unordered collection of attributes
c) Unordered collection of nodes
d) Unordered collection of arrays
View Answer

Answer: d
Explanation: In the HTML DOM, the NamedNodeMap object represents an unordered collection of an elements attribute nodes. The nodes in the NamedNodeMap can be accessed through their name.

5. What is the purpose of the Attr object in the HTML DOM?
a) Used to focus on a particular part of the HTML page
b) HTML Attribute
c) Used to arrange elements
d) CSS attribute
View Answer

Answer: b
Explanation: When a web page is loaded, the browser creates a Document Object Model of the page. In the HTML DOM, the Attr object represents an HTML attribute.
advertisement

6. What is the work of the form control elements in the HTML DOM?
a) User Interface elements
b) All the possible elements
c) Debugging elements
d) Collecting elements
View Answer

Answer: a
Explanation: Form control elements: The form object contains all the elements defined for that object such as text fields, buttons, radio buttons, and checkboxes. The elements collection returns a collection of all elements in a form.

7. How are the objects organized in the HTML DOM?
a) Class-wise
b) Queue
c) Hierarchy
d) Stack
View Answer

Answer: c
Explanation: The HTML DOM model is constructed as a tree of Objects. The objects are organized in the hierarchy format in the HTML DOM.
advertisement

8. Which of the following is a type of HTML DOM?
a) Legacy DOM
b) W3C DOM
c) IE4 DOM
d) All of the mentioned
View Answer

Answer: d
Explanation: IE4 document object model was introduced in Version 4 of Microsoft’s Internet Explorer browser. IE 5 and later versions include support for most basic W3C DOM features. All of the above mentioned are types of HTML DOM.

9. What is the purpose of the Legacy DOM?
a) Makes the scripting easier
b) Allows access to few keys and elements
c) Modify the nodes
d) Making the script modular
View Answer

Answer: b
Explanation: The Legacy DOM: This is the model which was introduced in early versions of JavaScript language. It is well supported by all browsers but allows access only to certain key portions of documents, such as forms, form elements, and images.
advertisement

10. Which object is the top of the hierarchy?
a) Window Object
b) Document Object
c) Form Object
d) Form Control Elements
View Answer

Answer: a
Explanation: The DOM is arranged in the form of tree with every node as an object. Window object is the top of the hierarchy. It is the outmost element of the object hierarchy.

Sanfoundry Global Education & Learning Series – Javascript Programming.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.