Javascript Events Flashcards

1
Q

HTML events are “things” that happen to HTML elements.
When JavaScript is used in HTML pages, JavaScript can “react” on these events.
HTML Events
An HTML event can be something the browser does, or something a user does.

Here are some examples of HTML events:

An HTML web page has finished loading
An HTML input field was changed
An HTML button was clicked
Often, when events happen, you may want to do something.

JavaScript lets you execute code when events are detected.

HTML allows event handler attributes, with JavaScript code, to be added to HTML elements.

With single quotes:
With double quotes:
In the following example, an onclick attribute (with code), is added to a button> element:
In the example above, the JavaScript code changes the content of the element with id=”demo”.
In the next example, the code changes the content of its own element (using this.innerHTML):
JavaScript code is often several lines long. It is more common to see event attributes calling functions:

A

element event=’some JavaScript’>

element event=”some JavaScript”>

button onclick=”document.getElementById(‘demo’).innerHTML = Date()”>The time is?/button>

button onclick=”this.innerHTML = Date()”>The time is?/button>

last example:
button onclick=”displayDate()”>The time is?/button>

script>
function displayDate() {
  document.getElementById("demo").innerHTML = Date();
}
/script>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Common HTML Events
Here is a list of some common HTML events:

What are the descriptions for these events:
onchange
onclick
onmouseover	
onmouseout
onkeydown
onload
A

Event Description
onchange An HTML element has been changed
onclick The user clicks an HTML element
onmouseover The user moves the mouse over an HTML element
onmouseout The user moves the mouse away from an HTML element
onkeydown The user pushes a keyboard key
onload The browser has finished loading the page

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

Common HTML Events
Here is a list of some common HTML events:

What are the events for these Descriptions:
An HTML element has been changed.
The user clicks an HTML element.
The user moves the mouse over an HTML element.
The user moves the mouse away from an HTML element.
The user pushes a keyboard key.
The browser has finished loading the page.

A

Event Description
onchange An HTML element has been changed
onclick The user clicks an HTML element
onmouseover The user moves the mouse over an HTML element
onmouseout The user moves the mouse away from an HTML element
onkeydown The user pushes a keyboard key
onload The browser has finished loading the page

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