Skip to content

Instantly share code, notes, and snippets.

@kaniket7209
Created November 25, 2021 05:28
Show Gist options
  • Save kaniket7209/f458e41dcb61871651c1673cc6ff81ed to your computer and use it in GitHub Desktop.
Save kaniket7209/f458e41dcb61871651c1673cc6ff81ed to your computer and use it in GitHub Desktop.
Browser Events (In-depth)
1. When should event handlers be loaded?
Answer: The load event occurs when the document has been completely loaded, including dependent resources like JS files, CSS files, and images. The <img> and <script> elements also support the load event. Use the addEventListener() method to register an onload event handler.
2. How do I stop click event propagation?
Answer: To stop an event from further propagation in the capturing and bubbling phases, you call the Event. stopPropation() method in the event handler.
3. Is it true that using stopPropagation() method in the event handler stops the default behaviours of the element?
Answer: No, the event stopPropagation() method doesn't stop any default behaviors of the element e.g., link click, checkbox checked.
4. How do I stop events bubbling?
Answer: If you want to stop the event bubbling, this can be achieved by the use of the event. stopPropagation() method.
5. How do you stop event capturing?
Answer: If a listener has been added to the capturing phase, rather than the bubbling phase, then you can prevent the event from capturing down to child elements with the same method: event. stopPropagation()
6. How do you implement event capturing?
Answer: In event capturing, an event propagates from the outermost element to the target element. It is the opposite of event bubbling, where events propagate outwards from the target to the outer elements.
7.Which event occurs first Capturing/Bubbling ?
Answer: Capturing happens before bubbling.
8. What is the difference between Capturing and Bubbling ?
Answer: With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. With capturing, the event is first captured by the outermost element and propagated to the inner elements.
9. What is the default value for activation of Bubbling and capturing Phase ?
Answer: if you pass true then it will activate capturing and if you pass false or not pass anything then it will activatebubling phase as by default bubbling is activated.
Ques 1: Which property specifies the property of the event?
a. type
b. target
c. manner
d. all of the above
Correct Answer : a
Ques 2: What are the three phases of the event flow?
a. hold, acquire and callback
b. listen, catch and register
c. capture, target and bubbling
d. addListener, callback and removeListener
Correct Answer: c
Ques 3: Every event satrts from :-
a. window
b. html
c. document
d. None of the above
Correct Answer:
Ques 4: in addEventListener() function what is the default phase?
a. capturing
b. bubbling
c. target
d. none of the above
Correct Answer: b
Ques 5: what we need to set To catch an event on the capturing phase in the addEventListener() function?
a. by making capture: true
b. by making cpature : false
Correct Answer: a
Ques 6: the ____ element triggers the event.
a. target
b. currentTraget
Correct Answer: a
Ques 7: the ________ is a element on which listener is attached
a. target
b. currentTraget
Correct Answer: b
Ques 8: what does '0' represents when we run e.eventPhase()?
a. capturing
b. bubbling
c. none
d. target
Correct Answer: c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment