0

Why isn't this code running

I have two images that need a popup when hovered over but when I put in the code it only executes the last code, what is wrong with my code and how do I fix it? function start() { alert("One Round, first person to 7 victory points") } window.onload = function() { let spo = document.getElementById("ca"); spo.onmouseover= start; }; function win() { alert("3 rounds") } window.onload = function() { let oon = document.getElementById("sp") oon.onmouseover= win;

25th Feb 2023, 2:24 AM
Kyler
Kyler - avatar
2 Answers
+ 8
Hello Kyler, I don't know whether that was the whole code but seems incomplete or truncated to me. Better save it as a code bit and attach its link in post Description for a better view of the problem. In case you didn't know yet how ... https://www.sololearn.com/post/75089/?ref=app
25th Feb 2023, 3:12 AM
Ipang
+ 2
You are overwriting the definition of the first window.overload with the last definition of the last window.onload. You could add the code from the first window.load to the last window.onload function start() { alert("One Round, first person to 7 victory points") } function win() { alert("3 rounds") } window.onload = function() { let spo = document.getElementById("ca") spo.onmouseover= start; let oon = document.getElementById("sp") oon.onmouseover= win;
26th Feb 2023, 2:54 PM
ODLNT
ODLNT - avatar