$(function() { $("object").each(function() { if ($(this).find("param[value^='http://www.youtube.com']").length > 0) { var parent = $(this).parent(); var youtubeCode = parent.html(); var params = ""; if (youtubeCode.toLowerCase().indexOf("<param") == -1) { $("param", this).each(function() { params += $(this).get(0).outerHTML; }); } var oldOpts = /rel=0/g; var newOpts = "rel=0&amp;hd=1&amp;color1=0x"+youtubeColor+"&amp;color2=0x"+youtubeColor; youtubeCode = youtubeCode.replace(oldOpts, newOpts); if (params != "") { params = params.replace(oldOpts, newOpts); youtubeCode = youtubeCode.replace(/<embed/i, params + "<embed"); } parent.html(youtubeCode); } }); });
