I haven't used much jquery and I can't do this:
I have a li with id="play1" on click on it: play a song and on click on "play1" again pause playback. So always, play / stop.
<li id="play1">
$( "#play1" ).click(function()
{
//si play1 click ejecutar audio1.play();
//otro click en play1 ejecutar audio1.pause();
});
use a counter?
Put a flag that indicates the state of the player. You can create the flag with JavaScript:
Or via an attribute
data-
:And you get the attribute on the click event:
DEMO in JS BIN
I leave you here an elegant example to be able to add more rows of audio without repeating the same code over and over again in jQuery.
Another way to do it is to use jquery's bind and unbind methods:
This way you attach the click event of the #play1 element to click_1 when executing the code and if click_1 executes, click_1 is unbound and click_2 is bound. Then on click_2, click_2 is unbound and click_1 is bound.