Simple pause and play button

I have an audio tag and a small div which I intend changing its text content based on whether the audio player is “active” or not. I wrapped the logic in the ready method but it does nothing besides initializing the div’s content. I’m typing from mobile and the text box of Sitepoint is so tiny, I can’t type code here. But I’ve posted it on this bin http://jsbin.com/kuqotigawe/edit?js,console,output

In the else clause, it’s the addClass part that’s causing you the trouble. Get rid of that and things will work fine.

Excluding the else clause just causes it to function only when it has the class i.e. when the music is playing. When the music is off and I want to restart it, I need the else to check and add the class accordingly. How do I go around this?

[quote=“nmeri17, post:3, topic:230218, full:true”]
Excluding the else clause just causes it to function only when it has the class[/quote]

No, I don’t mean to exclude the else clause.

What I mean is that the addClass part in the else clause is giving you the trouble. Remove that addClass part of the code in the else clause, and leave everything else as it is.

The problem with that addClass part in the else clause, is that it’s undoing the class name that resulted in the code getting in to that else clause in the first place, resulting in the if part of the statement never being executed.

By removing that addClass part that’s in the else clause, the if/else construct will then be able to work correctly.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.