Explanation:The addEventListener() method attaches an event handler to the specified element.
Incorrect! Try again.
17Which property allows you to read or change the class of an element as a string?
A.element.class
B.element.className
C.element.cssClass
D.element.classList
Correct Answer: element.className
Explanation:The className property sets or returns the class name of an element as a string.
Incorrect! Try again.
18Which property allows you to add or remove CSS classes easily using methods like .add() and .remove()?
A.element.className
B.element.classList
C.element.style
D.element.classes
Correct Answer: element.classList
Explanation:classList provides methods like add(), remove(), and toggle() to manipulate CSS classes.
Incorrect! Try again.
19What does 'document.write()' do?
A.Writes data to a specific element
B.Writes a stream of text to the document stream
C.Writes to the browser console
D.Saves data to a file
Correct Answer: Writes a stream of text to the document stream
Explanation:document.write() writes a string of text to a document stream opened by document.open(). Using it after page load overwrites the entire document.
Incorrect! Try again.
20Which attribute is used to access the attribute value of an HTML element?
A.element.attr(name)
B.element.getAttribute(name)
C.element.fetchAttribute(name)
D.element.attribute(name)
Correct Answer: element.getAttribute(name)
Explanation:getAttribute() returns the value of a specified attribute on the element.
Incorrect! Try again.
21How do you set an attribute on an element?
A.element.setAttribute(name, value)
B.element.attr(name, value)
C.element.createAttribute(name, value)
D.element.attribute = value
Correct Answer: element.setAttribute(name, value)
Explanation:setAttribute() adds the specified attribute to an element, and gives it the specified value.
Incorrect! Try again.
22Which event triggers when a web page has finished loading?
A.onready
B.onload
C.onfinish
D.onrender
Correct Answer: onload
Explanation:The onload event occurs when an object (like the body/page) has been completely loaded.
Incorrect! Try again.
23Which property provides the full URL of the current HTML document?
A.document.location
B.document.URL
C.window.link
D.document.href
Correct Answer: document.URL
Explanation:document.URL returns a string containing the URL of the current document.
Incorrect! Try again.
24What is the return type of 'document.querySelectorAll'?
A.Array
B.NodeList
C.HTMLCollection
D.String
Correct Answer: NodeList
Explanation:querySelectorAll returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors.
Incorrect! Try again.
25How do you prevent the default behavior of an event (like a form submission)?
A.event.stop()
B.event.halt()
C.event.preventDefault()
D.event.cancel()
Correct Answer: event.preventDefault()
Explanation:The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur.
Incorrect! Try again.
26Which DOM property is used to hide an element using CSS?
A.element.style.visibility = 'hidden'
B.element.style.display = 'none'
C.Both A and B
D.element.style.hidden = true
Correct Answer: Both A and B
Explanation:Setting display to 'none' removes it from layout. Setting visibility to 'hidden' hides it but keeps space. Both are valid ways to hide elements via DOM CSS.
Incorrect! Try again.
27What is the root element of the document.documentElement property?
A.<body>
B.<head>
C.<html>
D.<!DOCTYPE>
Correct Answer: <html>
Explanation:document.documentElement returns the Element that is the root element of the document (for HTML documents, this is the <html> element).
Incorrect! Try again.
28Which event fires when an input field loses focus?
A.onfocus
B.onblur
C.onchange
D.oninput
Correct Answer: onblur
Explanation:The onblur event occurs when an object loses focus.
Incorrect! Try again.
29How can you access the text content of a node and all its descendants?
A.node.text
B.node.textContent
C.node.content
D.node.string
Correct Answer: node.textContent
Explanation:textContent returns the text content of the specified node and all its descendants.
Incorrect! Try again.
30What does the 'this' keyword refer to inside an event handler function defined in HTML?
A.The global window object
B.The element that received the event
C.The document object
D.The javascript engine
Correct Answer: The element that received the event
Explanation:In an HTML event handler, 'this' refers to the HTML element that received the event.
Incorrect! Try again.
31Which method is used to remove an attribute from an element?
A.element.deleteAttribute()
B.element.removeAttribute()
C.element.clearAttribute()
D.element.dropAttribute()
Correct Answer: element.removeAttribute()
Explanation:removeAttribute() removes the specified attribute from an element.
Incorrect! Try again.
32How do you replace one child node with another?
A.parentNode.changeChild(new, old)
B.parentNode.replaceChild(new, old)
C.parentNode.swapChild(new, old)
D.parentNode.updateChild(new, old)
Correct Answer: parentNode.replaceChild(new, old)
Explanation:replaceChild() replaces a child node with a new node.
Incorrect! Try again.
33Which event is triggered when the user moves the mouse over an element?
A.onmouseenter
B.onmouseover
C.onhover
D.Both A and B
Correct Answer: Both A and B
Explanation:Both onmouseover and onmouseenter trigger when the mouse moves over an element (though bubbling behavior differs).
Incorrect! Try again.
34What is 'event bubbling'?
A.Events firing from the target element up to the root
B.Events firing from the root down to the target
C.Events firing only on the specific element
D.Events canceling each other out
Correct Answer: Events firing from the target element up to the root
Explanation:Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors.
Incorrect! Try again.
35Which method stops the propagation of an event in the bubbling or capturing phase?
A.event.stop()
B.event.pause()
C.event.stopPropagation()
D.event.prevent()
Correct Answer: event.stopPropagation()
Explanation:stopPropagation() prevents further propagation of the current event in the capturing and bubbling phases.
Incorrect! Try again.
36How do you change the font size of an element to 20px using JavaScript?
A.element.style.fontsize = '20px'
B.element.style.fontSize = '20px'
C.element.style.font-size = '20px'
D.element.style.textSize = '20px'
Correct Answer: element.style.fontSize = '20px'
Explanation:The CSS property 'font-size' is written as 'fontSize' in JavaScript (camelCase).
Incorrect! Try again.
37What property holds the title of the document defined in the <title> tag?
A.document.header
B.document.name
C.document.title
D.document.meta
Correct Answer: document.title
Explanation:document.title gets or sets the title of the document.
Incorrect! Try again.
38If 'document.getElementById' does not find an element, what does it return?
A.undefined
B.null
C.false
D.An empty array
Correct Answer: null
Explanation:If no element with the specified ID exists, the method returns null.
Incorrect! Try again.
39Which collection returns all <img> elements in the document?
A.document.pictures
B.document.imgs
C.document.images
D.document.graphics
Correct Answer: document.images
Explanation:document.images is a read-only property that returns a collection of all <img> elements in the document.
Incorrect! Try again.
40What is the purpose of 'document.forms'?
A.Creates a new form
B.Submits a form
C.Returns a collection of all forms in the document
D.Validates a form
Correct Answer: Returns a collection of all forms in the document
Explanation:The forms property returns a collection (an HTMLCollection) of all <form> elements in the document.
Incorrect! Try again.
41Which of the following is NOT a valid node type?
A.Element Node
B.Text Node
C.Attribute Node
D.Data Node
Correct Answer: Data Node
Explanation:Standard DOM node types include Element, Text, Attribute, Comment, and Document. 'Data Node' is not a standard DOM node type.
Incorrect! Try again.
42Which method allows you to insert a new node before an existing node?