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.
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>
请改用小写的"mouseover"
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.