Domanda

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

È stato utile?

Soluzione 2

the problem is that you are changing src in wrong id

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top