JavaScript MCQs – DOM Manipulation and Events is an important topic for interview preparation. It focuses on working with DOM elements, handling events, and understanding concepts like event propagation, delegation, and methods such as addEventListener and querySelector. Practicing MCQs on these topics helps you build a strong foundation and prepares you for coding interviews.
1.) What does DOM stand for in JavaScript?
A) Data Object Model
B) Document Object Model
C) Dynamic Object Model
D) Document Oriented Model
2.) Which method is used to select an element by its ID in JavaScript?
A) getElementByClass
B) getElementsByTag
C) getElementById
D) querySelector
3.) What does querySelector() do?
A) Selects all elements of a given type.
B) Selects the first matching element.
C) Selects elements by class only.
D) Selects elements by ID only.
4.) How can you add a new child element to an existing DOM element?
A) appendChild()
B) addChild()
C) createChild()
D) insertChild()
5.) Which property is used to access or change the content of an HTML element?
A) innerContent
B) innerText
C) innerHTML
D) outerHTML
6.) What will the following code do?
document.getElementById("myDiv").style.color = "red";
A) Do nothing.
B) Throw an error.
C) Change the background color of myDiv to red.
D) Change the text color of myDiv to red.
7.) How do you attach a click event to a button in JavaScript?
A) button.onClick = function() { … }
B) button.addEventListener(“click”, function() { … })
C) button.attach(“click”, function() { … })
D) Both A and B
8.) What does the preventDefault() method do in an event handler?
A) Stops the execution of the event handler.
B) Stops the event from propagating.
C) Prevents the default action of the event.
D) Removes the event listener.
9.) How can you remove an existing child element in the DOM?
A) removeChild()
B) deleteChild()
C) removeElement()
D) clearChild()
10.) What is the difference between stopPropagation() and preventDefault()?
A) Both stop the event from propagating.
B) Both prevent the default behavior.
C) stopPropagation() stops event bubbling, while preventDefault() stops the default action.
D) There is no difference.
Related