[quote=“Paul_Wilkins, post:163, topic:278598, full:true”]The problem is that you’ve made the onmouseover and onmouseout code exactly the same.
[/quote]
When you mouse out, you want the pause to hide and the speaker to show. Update the onmouseout code so that it does that.
I have a question, how come I was originally told to use addEventListener, and would that have worked the same way, and, or, maybe that doesn’t belong in this type of code setup?
Instead of the onmouseover and onmouseout sections, addEventListener could have been used in the onclick code, where you give it a function that contains what was in each of those sections.
Yep. The onclick code happens every time you click on the button, so the second time you click on it, a second set of mouse events would have been added. Eventually you would have hundreds of mouse events being run whenever you click, increasing each time. That is bad.
If you want to use addEventListener though, you can use it at the end of the body, in a <script> block of code instead.
I prefer to order the attributes in terms of importance. The onmouse stuff doesn’t do anything until after the button has been clicked, so moving them after the onclick code makes a lot of sense.
and those event handlers are as simple as the following code:
function showPauseHandler() {
if (isPlaying()) {
show("pause");
}
}
function showSpeakerHandler() {
if (isPlaying()) {
show("speaker");
}
}
That’s all that it takes. When the code is well built, making such changes are easy and effortless, instead of being the slog that we went through here in the previous posts.