JavaScript Questions & Answers – Scripting Documents

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

1. The central object in a larger API is known as __________
a) Document Object Material
b) Document Object Model
c) Binary Object Model
d) Data object model
View Answer

Answer: b
Explanation: Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document. It is the central object in a larger API, known as the Document Object Model, or DOM, for representing and manipulating document content.

2. The paragraph “p” is a part of __________
a) h1
b) body
c) html
d) both body and html
View Answer

Answer: d
Explanation: The paragraph tag belongs to both html and body tag. It is used to write paragraph on html pages.

3. The node directly above a node is called __________
a) sibling
b) child
c) parent
d) ancestors
View Answer

Answer: c
Explanation: The node directly above a node is the parent of that node. In HTML, the document itself is the parent node of the HTML element, HEAD and BODY are child nodes of the HTML element.
advertisement
advertisement

4. The Text and Comment is part of __________
a) CharacterData
b) Document
c) Attr
d) Element
View Answer

Answer: a
Explanation: The CharacterData abstract interface represents a Node object that contains characters. This is an abstract interface, meaning there aren’t any object of type CharacterData. The Text and Comment is part of the CharacterData Element.

5. The nodes that represent HTML elements are the __________
a) Subclass nodes
b) HTML nodes
c) Window nodes
d) Element nodes
View Answer

Answer: d
Explanation: The nodes that represent HTML elements are Element nodes. The various html elements include h1, p, div etc.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which of the following is/are of Text nodes?
a) Text
b) Comment
c) Both Text and Comment
d) h1
View Answer

Answer: c
Explanation: Both Text and Comment are basically strings of text, and these nodes are much like the Text nodes that represent the displaying text of a document.

7. Which is not the way to query a document for an element or elements?
a) With a specified id attribute
b) Matching the specified CSS selector
c) With the specified tag name
d) without the specified CSS class or classes
View Answer

Answer: d
Explanation: The DOM defines a number of ways to select elements; you can query a document for an element or elements:

  1. with a specified id attribute;
  2. with a specified name attribute;
  3. with the specified tag name;
  4. with the specified CSS class or classes; or
  5. matching the specified CSS selector
advertisement

8. Which of the following can be used to select HTML elements based on the value of their name attributes?
a) getElementByName()
b) getElementsByName()
c) getElementsName()
d) getElementName()
View Answer

Answer: b
Explanation: The getElementsByName() method returns a collection of all elements in the document with the specified name (the value of the name attribute), as a NodeList object.

var radiobuttons = document.getElementsByName("favorite_color");

9. Which of the following property refers to the root element of the document?
a) documentElement
b) elementdocument
c) rootdocument
d) rootelement
View Answer

Answer: a
Explanation: The documentElement property of the Document class refers to the root element of the document. This is always an HTML element. The documentElement property returns the documentElement of the document, as an Element object.
advertisement

10. The return type of getElementsByClassName() is __________
a) DOM
b) Document
c) Node
d) NodeList
View Answer

Answer: d
Explanation: The getElementsByClassName() method returns a collection of all elements in the document with the specified class name, as a NodeList object. The other methods of returning nodelist objects are getElementsByTagName(), getElementbyId() etc.

Sanfoundry Global Education & Learning Series – Javascript Programming.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

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 & discussions at Telegram SanfoundryClasses.