- 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" />
// 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" />
// index.js
const button = document.getElementById("notify")
button.addEventListener('mouseover', function(){
console.log("Printing a Message!")
})
// index.html
...
<script src="index.js" />
<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" />
<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" />
<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!")
})
});
Team members: Ameen, Ali Majid, Hevar, Mhamad Othman, Aland.
1- When ever the button is clicked it's print "Printing a Message!"
2- When ever you hover on the button it will print "Printing a Message!"
3- it will not print anything in the console
4- Whenever you hover on the button it will print the messege in the console, so the event listener waited for the button to be loaded
5- "addListenerEvent" is not a function so this will accure an error.