YouTube API, jQuery attr won't swap element attributes (I think) in IE, but works in FF

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-04-27T00:23:00Z Indexed on 2010/04/27 20:43 UTC
Read the original article Hit count: 214

Filed under:
|
|
|
|

JavaScript (jQuery)

function display_youtube(new_url) {
    $('#movie_url').removeAttr('value');
    $('#embed_url').removeAttr('src');
    $(document).ready(function() {
        $('#movie_url').attr('value', new_url);
        $('#embed_url').attr('src', new_url);
        $('#shade').css('display', 'block');
        $('#youtube_player').css('display', 'block');
        $('#exit_youtube').css('display', 'block');
    });
}

HTML

<object width="720" height="480">
<param id="movie_url" name="movie" value="http://www.youtube.com/v/_eaToCSn7yU?f=user_uploads&app=youtube_gdata&autoplay=0" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<embed id="embed_url" src="http://www.youtube.com/v/_eaToCSn7yU?f=user_uploads&app=youtube_gdata&autoplay=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="720" height="480" />
</object>

Hyperlink

<a href="javascript:display_youtube('http://www.youtube.com/v/_eaToCSn7yU?f=user_uploads&app=youtube_gdata&autoplay=1');">Click Here for Fun!</a>

What I've done is parsed YouTube's API for the videos on my user channel. The hyperlink above is php generated, meant to trigger the above JavaScript function, and swap the url from attributes contained in ids "movie_url" and "embed_url". Works just like it should in FF, but IE will only perform the .css commands. My guess? IE doesn't like me assigning IDs to PARAM and EMBED, perhaps? What do you think?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about attr