Event Handling Flashcards

1
Q

Events

A
  • Actions or Occurrences that happen in the system or your application, which the system tells you about so you can respond.
  • When the user takes an action, like click a mouse button, the Operating System “screams” out to any application that is interested that the event occurred.
  • Applications that are interested in that event register an Event Listener that “hears” the event and allows the program to take action.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Web Events

A
  • When a user takes an action in the browser window, the browser raises an event letting the application running it know that the event occurred.
  • Everything the user does raises some sort of event, or sometimes multiple events, allowing the programmer to choose what events they care about and what actions they want to take in response.
  • Many of the actions the browser or HTML elements take are also raised as events that can be handled.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Event Handling

A

The receipt of an event at some event handler that was raised by an event producer. The event producer raises the event (the user clicked on a button), the event handler receives the event and forwards it to a callback function, which is a function in our code that will react to the event. Event handling is managed in JavaScript not CSS or HTML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Event Handler

A
  1. Code in our JavaScript that reacts when an event occurs.
  2. A callback function that will be called by the Event Listener, which what “hears” the event, when the event occurs (usually an anonymous function),
    includes an optional parameter to receive the Event Object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Event Object

A

An object that is passed to the event handler callback function that details the event the Target: what was the focus of the event (example: what the user actually clicked on) the event’s location mouse events: includes which mouse was a button was used keyboard: which key was pressed. Each event type has an event object with information unique to that event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Event Listeners

A

This tells the browser that we are interested in the event and want to react to it.
When the EventListener a callback method is provided. When the EventListener is informed that the event has occurred it will call our callback method. In JavaScript, we provide a callback method as an anonymous function that we pass to the event listener when we create it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

DOMContentLoaded

A
Is raised on the document when the HTML has been fully loaded into the DOM and is ready for manipulation
all functionality (not variable declarations) that is not in a Function should be only run once this event has been raised functions should be declared outside of this event. Many example show to use the load event, but that does not guarantee the DOM has been created, so always use DOMContentLoaded to verify the page is ready to be manipulated by JavaScript.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Event Propagation

A
  1. When an event is raised on a DOM element every parent of that element is also notified.
  2. 3 Phases:
    - Capture phase
    - Target phase
    - Bubble phase
  3. Can stop propagation by calling: stopPropagation() on the event object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Event Propagation Capture phase

A

Starts at the document and notifies every element in the hierarchy until it reaches the target element - off by default but can be enabled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Event Propagation Target phase

A

The target element (for example the button the user clicked on) is notified of the event - always is included

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Event Propagation Bubble phase

A

Starts at the target and notifies all of the parents in the hierarchy of the target - this is the default for the browser event handler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

DOMContentLoaded

A
  1. Is raised on the document when the HTML has been fully loaded into the DOM and is ready for manipulation.
  2. All functionality (not variable declarations) that is not in a Function should be only run once this event has been raised functions should be declared outside of this event.
  3. Many example show to use the load event, but that does not guarantee the DOM has been created, so always use
  4. DOMContentLoaded to verify the page is ready to be manipulated by JavaScript.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly