We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,285 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

HTML5 - Dynamic song change

My code goes something like this:

<div class="pBody">
<audio id="player" name="player" class="player" src="" controls="controls"></audio>
</div>  

    $(document).ready(function(){
        $('.fileTr').click(function() {
            var id=this.id;
            $('#player').attr("src","../mmc/FileSet/" + id);
            var sr = $('#player').attr("src");
            alert(sr);
            $("#player")[0].play();
        });
    });

fileTr is a class of table columns each having the file name as its id.

What I am trying to do is, when a person clicks a particular column then the id is passed to the function which sets the 'src' attribute for the audio tag and generates a play event. But its not working!

Thanks!

2
Contributors
1
Reply
1 Day
Discussion Span
2 Years Ago
Last Updated
2
Views
iammirko
Light Poster
33 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

It seems that line 11 would give error as JQuery id selector returns single element not array.

$("#player").play();

Also check by hard coding the path of audio file in above function(that is without using id)

Luckychap
Posting Pro in Training
445 posts since Aug 2006
Reputation Points: 83
Solved Threads: 61
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0571 seconds using 2.68MB