tags:

views:

3211

answers:

1

I've been having trouble in trying to figure this out. What I am trying to do is, obtain the ID of a video from YouTube, and input the 11 character ID into the css of a div of a specific id by using jquery. I know the URL for the thumbnail of any video, but I just need to be able to change the ID to display different video thumbnails.

<script>
$(document).ready(function() {

    function(data){
        videoID = data.split('www.youtube.com/v/')[1].split('&amp')[0];
        $("#304817679").append(videoID);
        });
        $("#304817679").replaceWith("<div  id=\"304817679\" style=\"background: url(http://img.youtube.com/vi/"+ $.function(data) +"/0.jpg) no-repeat middle; width: 15px; height: 150px;\"></div>");
        });
});
</script>

        <div id="304817679">
            <div style="display: none;"><object width="248" height="222"><param name="movie" value="http://www.youtube.com/v/vy90n2nNRKQ&amp;amp;rel=0&amp;amp;egm=0&amp;amp;showinfo=0&amp;amp;fs=1"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/vy90n2nNRKQ&amp;amp;rel=0&amp;amp;egm=0&amp;amp;showinfo=0&amp;amp;fs=1" type="application/x-shockwave-flash" width="248" height="222" allowFullScreen="true" wmode="transparent"></embed></object></div>
        </div>

Trying to explain this better, I want the 11 Character YouTube Video ID from the embedded code, and put it into the URL of the thumbnail (http://img.youtube.com/vi/"+ function(data) +"/0.jpg). Which, would then also replace the original div (div id="304817679").

Am I on the right track with my script? I'm entirely new to this, and I would appreciate some of the help that's offered here.

A: 

OK, so what you really want is how to find and replace a text, it seems. Take a look at http://stackoverflow.com/questions/233922/find-replace-jquery

Or are you having problems even with getting and setting the attribute at all?

Eduardo
Dave
So, it's a matter of finding the regex to match the text between the 2 slashes. Let us know how you progress on this :)
Eduardo