Jquery replace string
May sound like a total noob question but i'm looking for a开发者_运维知识库 javascript (and or jquery) function to replace an element in this code :
<embed id="ply" width="800" height="400"
flashvars="file=http://example.com/play/"
allowscriptaccess="always"
allowfullscreen="true"
quality="high" bgcolor="#00000"
name="ply" style=""
src="/video-player.swf"
type="application/x-shockwave-flash"/>
I want to be able to replace the :
flashvars="file=http://example.com/play/"
and append some text (for video seeking) :
flashvars="file=http://example.com/play/234983"
Must be really easy to do, but i'd appreciate help for some more experienced user.
$("#ply").attr("flashvars", $("#ply").attr("flashvars") + "/234983");
Update
If you want to reload the player, this may work. It will clone the existing embed tag with the ID ply
, only replacing the flashvars
attribute value. This effectively removes ply
from the DOM and then inserts it in place again. This would hopefully cause the browser to reload the player.
var p = $("#ply");
p.replaceWith(p.clone().attr("flashvars", p.attr("flashvars") + "/234983"));
精彩评论