Search code examples
javascriptjqueryembedsrc

How to change the src value of object/embed tag using jquery


<object id="aa" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="650" height="400">
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<param name="movie" value="test.swf">
<embed src="test.swf" type="application/x-shockwave-flash" width="650" height="400"  bgcolor="#000000">
</object>

i want to change the value of src inside embed tag

  src="test.swf" to  src="newlink.swf"

tried something like this but not work.

            $("#aa").attr('src' 'new link'); 

Solution

  • You need to use ID Selector ("#id")

     $("#aa embed").attr('src', 'new link'); 
    

    OR

     $("#aa").find('embed').attr('src', 'new link');
    

    DEMO

    EDIT

    var aa =  $("#aa").clone();
    aa.find('embed').attr('src', 'http://jquery.thewikies.com/swfobject/fireworks.swf')
    $("#aa").replaceWith(aa);
    alert( $("#aa").find('embed').attr('src'));
    

    DEMO