JavaScript Questions & Answers – Text Events

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

1. When are the mouse events generated?
a) When user clicks the mouse over a document
b) When user moves over a document
c) On pressing a key
d) When user clicks or moves the mouse over a document
View Answer

Answer: d
Explanation: Mouse events are generated when the user moves or clicks the mouse over a document. These events are triggered on the most deeply nested element that the mouse pointer is over, but they bubble up through the document.

2. The properties that specify the position and button state of the mouse are _________
a) clientX and clientY
b) clientY and clientX
c) altKey and ctrlKey
d) metaKey and shiftKey
View Answer

Answer: a
Explanation: The clientX and clientY properties specify the position of the mouse in window coordinates. The clientX property returns the horizontal coordinate (according to the client area) of the mouse pointer when a mouse event was triggered. Similarly clientY returns the vertical coordinates.

3. Which of the following keys are not set to true when the keyboard modifier keys are held down?
a) altKey
b) ctrlKey
c) metaKey
d) delkey
View Answer

Answer: d
Explanation: A modifier key is a key that modifies the action of another key when the two are pressed together. The altKey, ctrlKey, metaKey, and shiftKey properties are set to true when the corresponding keyboard modifier keys are held down.
advertisement
advertisement

4. How to detect and respond to mouse drags?
a) Registering a mouseover handler
b) Releasing a mousedown handler
c) Registering a mousedown handler
d) Releasing a mouseover handler
View Answer

Answer: c
Explanation: By registering a mousedown handler that registers a mousemove handler, you can detect and respond to mouse drags. Doing this properly involves being able to capture mouse events so that you continue to receive mousemove events even when the mouse has moved out of the element it started in.

5. When is the mouseover event fired?
a) When mouse is moved over a new element
b) When mouse is clicked
c) When mouse is both moved and clicked
d) When mouse is released
View Answer

Answer: a
Explanation: When the user moves the mouse so that it goes over a new element, the browser fires a mouseover event on that element. The onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children.

6. When is the mouseout event fired?
a) When mouse is no longer over an element
b) When mouse is over an element
c) When mouse is hovered
d) When mouse is clicked
View Answer

Answer: a
Explanation: When the mouse moves so that it is no longer over an element, the browser fires a mouseout event on that element. The mouseout() method triggers the mouseout event, or attaches a function to run when a mouseout event occurs

7. The focus and blur events are also part of _________
a) Element events
b) Handler events
c) Window events
d) Scroll events
View Answer

Answer: c
Explanation: The focus and blur events are also used as Window events: they are triggered on a window when that browser window receives or loses keyboard focus from the operating system. Focusin and onblur methods are used for using these events.
advertisement

8. The element that can also register handlers for load and error events is _________
a) html
b) img
c) body
d) form
View Answer

Answer: b
Explanation: Individual document elements, such as img elements, can also register handlers for load and error events.onload and onerror methods are used for handling such events.

9. The events that are emulated by the jQuery library are _________
a) focusarea and focusover
b) focusall and focusnone
c) focusdown and focusup
d) focusin and focusout
View Answer

Answer: b
Explanation: The jQuery library emulates focusin and focusout events for browsers that do not support them. The focusin and focusout events bubble, the focus and blur events doesn’t. That means that you can use the focusin and focusout on the parent element of a form field.
advertisement

10. Which event is triggered sooner when the document and its elements are ready to manipulate?
a) DOMContentLoaded
b) readystatechange
c) Both DOMContentLoaded & readystatechange
d) Statechange
View Answer

Answer: c
Explanation: DOMContentLoaded and readystatechange are alternatives to the load event: they are triggered sooner, when the document and its elements are ready to manipulate, but before external resources are fully loaded.

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