Search code examples
javascriptjqueryhtmlhtml5-audio

Javascript: how to use multiple play buttons in audio player


So i'm trying to use two play buttons in my audio player, this is because i have one in audio player and other in sidebar for example.

Follows my jsfiddle: http://jsfiddle.net/LqM9D/5/

Someone can help?

Obs: i'm using html5 audio and jquery/js on my player


Solution

  • You're re-using the same ID twice. IDs must be unique. Correct that and it works fine. And since you're using jQuery, you could use:

    window.player = $('#player')[0];
    $('#playpause, #playpause2').click(function () {
        if (player.paused) {
            player.play();
            this.innerHTML = 'pause';
        } else {
            player.pause();
            this.innerHTML = 'play';
        }
    })
    

    jsFiddle example