0

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 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have to wait 9 mins to mark the answer by the way haha
1

the problem is that you are changing src in wrong id

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.