2

A simple question,

How to detect all <object> tag in the dom and add <param name="wmode" value="transparent"> or change its 'wmode' to transparent using jquery.

Thanks in advance.

Trez
  • 1,140
  • 5
  • 16
  • 23

1 Answers1

4

jQuery code like this will attempt to change the parameter.

$('object').each(function(index, elem) {
    var wmode = elem.children('param[name="wmode"]');
    if(!wmode.length) {
        elem.append('<param name="wmode" value="transparent"/>');
    } else {
        wmode.attr('wmode', 'transparent');
    }
});

However, this will not achieve the desired effect; you need to completely delete and recreate the object for the change to actually take effect. (I've tried, in the past, temporarily removing and then re-adding the object tag, without cross-browser success.) You may want to look at the SWFObject library. There's even a jQuery plugin for it.

PleaseStand
  • 31,641
  • 6
  • 68
  • 95
  • +1 for noting that this probably isn't going to work in IE. From my past experience, IE will not listen to changes in `object` tags. To get around this, I have tried, with varying success, to remove the `object` element completely and create and insert a new element with your desired properties. – wsanville Nov 11 '10 at 02:55