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
icon
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
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Image Element
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning