I have a scenario where I am using this code to control the playback of song samples, and there are multiple instances of it on the page. I am looking to enhance this functionality by adding some code that will change the background-image of only the specific instance with the .playback class to pausebutton.gif after the song is played. Furthermore, when the button is pressed again, I want it to change back to playbutton.gif. Since there are multiple instances on the page, I am wondering if this can be achieved using a class. Any assistance on how to implement this would be greatly appreciated. Thank you.
<script type="text/javascript>
$(function() {
$(".playback").click(function(e) {
e.preventDefault();
var song = $(this).next('audio').get(0);
if (song.paused)
song.play()
else
song.pause()
});
});
<style>
.playback:link
{background:url('images/playbutton.gif');display:block;width:18px;height:18px;}
</style>
<a class="playback" href="#"></a><audio id="wonderful"><source src="audio/wonderful.mp3" type="audio/mpeg" /></audio>