- Recall the different types of JavaScript Events
- Identify when the
DOMContentLoaded
event will trigger - Implement a callback attached to an event handler
Take a look at each of the code samples below. For each sample, work with your group to answer the following questions.
- What does each line of code do?
- How does this piece of code work?
- Given this code sample, what can you learn or describe about JavaScript
// index.html
...
<button id="notify">Click Me!</button>
<script src="index.js"></script>
// index.js
const button = document.getElementById("notify")
button.addEventListener('click', function(){
console.log("Printing a Message!")
})
// index.html
...
<button id="notify">Click Me!</button>
<script src="index.js"></script>
// index.js
const button = document.getElementById("notify")
button.addEventListener('mouseover', function(){
console.log("Printing a Message!")
})
// index.html
...
<script src="index.js"></script>
<button id="notify">Click Me!</button>
// index.js
const button = document.getElementById("notify")
button.addEventListener('mouseover', function(){
console.log("Printing a Message!")
})
// index.html
...
<script src="index.js"></script>
<button id="notify">Click Me!</button>
// index.js
document.addEventListener("DOMContentLoaded", function(){
const button = document.getElementById("notify")
button.addEventListener('mouseover', function(){
console.log("Printing a Message!")
})
});
Oops. Looks like this developer made some mistakes typing. Identify the mistakes.
// index.html
...
<script src="index.js"></script>
<button id="notifiable">Click Me!</button>
// index.js
document.addListenerEvent("DOMContentLoaded", function(){
const button = document.getElementById("notifliable")
button.addListenerEvent('click', function(){
console.log("Printing a Message!")
})
});