문제

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

도움이 되었습니까?

해결책 2

the problem is that you are changing src in wrong id

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top