- 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!")
})
});
Room 4,
hala,huda,darya,noor
example1
1-declaration, listing to button click and trigering function,printing the message on the console
2-on clicking the button,user will see a message on the consle
3-javascript listen to the event on clicking
example2
1-declaration, listing to button click and trigering function,printing the message on the console
2-onhovering the button,user will see a message on the consle
3- we can learn mouse over event listening.
example 3
1-declaration, listing to button click and trigering function,printing the message on the console
2-onhovering the button,user will see a message on the consle
3-javascript is only worked when the html is loaded
example 4
same as before
The DOMContentLoaded event fires when the HTML document has been completely parsed,
example5
same as before but with the wrong id
addListenerEvent should be .addEventListener.