Question

I am trying to change the src attribute to play a youtube video within javascript but cannot seem to get it to work.

Here is the statement I have been trying to use:

$("#youtube-player").setAttribute('src', obj[i].SongURL);

Here is the HTML:

<div id="youtube-player">
     <embed id="player" width="420" height="345"
            type="application/x-shockwave-flash" />
</div>

obj[i] has the correct data FYI

Was it helpful?

Solution 2

the problem is that you are changing src in wrong id

$("#player").attr('src', obj[i].SongURL);

OTHER TIPS

You are setting the src attribute of a div not the embed tag try the following.

$("#youtube-player > embed").attr('src', obj[i].SongURL);

or better yet select #player like @LOL suggests above :P

Demo width video tag

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top