0

I'm new to javascript and can't figure out why the following code isn't working:

var toChange = document.getElementById("greeting");
toChange.addEventListener("mouseOver", function() {
  this.innerHTML = "Hi";
  });
  <p id="greeting">Hello.</p>

I've thoroughly researched event listeners, and I can't figure out why this code won't work. Thank you.

2 Answers 2

5

Event names are case-sensitive. Here's your code, with mouseOver replaced with mouseover.

var toChange = document.getElementById("greeting");
toChange.addEventListener("mouseover", function() {
  this.innerHTML = "Hi";
  });
  <p id="greeting">Hello.</p>

Sign up to request clarification or add additional context in comments.

Comments

2

Use "mouseover" in lowercase instead.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.