.detach()。appendTo(parent)
を使用しているようです: http:// jsfiddle .net/pimvdb/b7Jgh/。
$("#oggSource").attr("src", "foo.ogg").detach().appendTo("#audioPlayer");
I guess the browser only starts loading (and playing with autoplay
) if a
element is added, not when it is just modified. I'm not sure why though, but appending it after detaching works.
Edit: You can also directly do .appendTo
since an element is unique (i.e. it has to be detached anyway): http://jsfiddle.net/pimvdb/b7Jgh/6/.
function updateSource(source, src) {
source = $(source);
source.attr("src", src).appendTo(source.parent());
}