Change WMode with jQuery

Submitted by:James Anderson

Date added:07 February, 2011

Category:jQuery

If you don't set the wmode on a flash embed it will float over the top of an overlay which can be a pretty big deal. This is ideal in environment with lots of legacy video code or where users will be posting new code and teaching them about wmode is a lost cause. This should work in all browsers.

Tags: change wmode , wmode jquery , flash embed

Code Snippet:

$("embed").attr("wmode", "opaque");<br />
var embedTag;<br />
$("embed").each(function(i) {<br />
embedTag = $(this).attr("outerHTML");<br />
if ((embedTag != null) && (embedTag.length > 0)) {<br />
embedTag = embedTag.replace(/embed /gi, "embed wmode="opaque" ");<br />
$(this).attr("outerHTML", embedTag);<br />
} else {<br />
$(this).wrap("<div></div>");<br />
}<br />
});
 
 

Comments