JavaScript Dom Manipulation Hi can anyone please help me fix my main.js file. We're not allowed to change anything in index.html. We have to make a button so that every time you click on it the count on the web page increases by one. My code doesn't work and I don't know why. Every time I click the button, nothing happens. We just started learning about DOM and the only method we've learned so far is document.querySelector() Please help me understand dom events better. thank you so much! var numTimesClicked = 0; /* function handleClick(event) { numTimesClicked++; console.log('button clicked'); console.log('value of numTimesClicked:', numTimesClicked); } var $hot = document.querySelector('.hot-button'); var $click = document.querySelector('.click-count'); $click.addEventListener('click', handleClick); */ function handleClick(event) { numTimesClicked++; console.log('button clicked'); console.log('event:', event); console.log('event.target', event.target); } var $click = document.querySelector('.click-count'); $click.addEventListener('click', handleClick); function handleMouseover(event) { console.log('button hovered'); console.log('event:', event); console.log('event.target', event.target); }
JavaScript Dom Manipulation Hi can anyone please help me fix my main.js file. We're not allowed to change anything in index.html. We have to make a button so that every time you click on it the count on the web page increases by one. My code doesn't work and I don't know why. Every time I click the button, nothing happens. We just started learning about DOM and the only method we've learned so far is document.querySelector() Please help me understand dom events better. thank you so much! var numTimesClicked = 0; /* function handleClick(event) { numTimesClicked++; console.log('button clicked'); console.log('value of numTimesClicked:', numTimesClicked); } var $hot = document.querySelector('.hot-button'); var $click = document.querySelector('.click-count'); $click.addEventListener('click', handleClick); */ function handleClick(event) { numTimesClicked++; console.log('button clicked'); console.log('event:', event); console.log('event.target', event.target); } var $click = document.querySelector('.click-count'); $click.addEventListener('click', handleClick); function handleMouseover(event) { console.log('button hovered'); console.log('event:', event); console.log('event.target', event.target); }
New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter5: Designing For The Mobile Web: Creating A Mobile Website For A Daycare Center
Section: Chapter Questions
Problem 2CP2
Related questions
Question
JavaScript Dom Manipulation
Hi can anyone please help me fix my main.js file. We're not allowed to change anything in index.html. We have to make a button so that every time you click on it the count on the web page increases by one.
My code doesn't work and I don't know why. Every time I click the button, nothing happens. We just started learning about DOM and the only method we've learned so far is document.querySelector() Please help me understand dom events better. thank you so much!
var numTimesClicked = 0;
/* function handleClick(event) {
numTimesClicked++;
console.log('button clicked');
console.log('value of numTimesClicked:', numTimesClicked);
}
var $hot = document.querySelector('.hot-button');
var $click = document.querySelector('.click-count');
$click.addEventListener('click', handleClick); */
function handleClick(event) {
numTimesClicked++;
console.log('button clicked');
console.log('event:', event);
console.log('event.target', event.target);
}
var $click = document.querySelector('.click-count');
$click.addEventListener('click', handleClick);
function handleMouseover(event) {
console.log('button hovered');
console.log('event:', event);
console.log('event.target', event.target);
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning