如何从iframe标记中删除样式(不在iframe内部,但在标记内)

时间:2013-04-30 06:55:15

标签: javascript jquery iframe

我的服务器上的页面有多个具有不同ID的iframe标记。我添加了一个iframe标记来嵌入YouTube视频。 iframe标签有一个样式元素,可以通过插件添加250宽度和250高度。我想删除添加到iframe的此样式,以便youtube视频在iframe标记的高度和宽度中仅显示此特定iframe,因为页面上的其他iframe标记具有不应触及的样式。

1)我正在添加的代码(通知宽度= 640高度= 390)

<iframe id="player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/GxTl1Ykbuww?enablejsapi=1&origin=origin-domain.com" frameborder="0"></iframe>

2)加载浏览器时在页面上显示的代码(请注意,style="height:250;width:250;"现已添加到iframe代码中,这是我想要删除的垃圾,但仅限于此iframe代码ID

<iframe id="player" style="height: 250px; width: 250px;" src="http://www.youtube.com/embed/GxTl1Ykbuww?enablejsapi=1&amp;origin=origin-domain.com" height="390" width="640" frameborder="0"></iframe>

Javascript或Jquery会很好。但jquery中的remove标记从页面上的每个iframe中剥离样式。

理想的解决方案只会导致id="player"的iframe从上面的2)更改为不再具有style=""或者具有style =“”但内部没有任何内容。

4 个答案:

答案 0 :(得分:2)

$('#player').removeAttr('style')

应该使用最新的jQuery

作为解释

$('#player')

以id ='player'为目标的DOM元素(#target id,就像css选择器一样)。

removeAttr('style')

从目标对象中删除'style'属性

答案 1 :(得分:1)

document.getElementById('player').removeAttribute('style')

我认为不应该使用jQuery或任何其他JS库

CSS解决方案:#player { width: 640px !important; height: 390px !important; }但使用!important是不好的做法。

答案 2 :(得分:0)

Try with ,
For style change :
$("#player").css("Height","90");

For attribute change :
$("#player").attr("Height","90");

For inside of iframe tag attribute or style change :
$("#player div").attr("Height","90");
$("#player div").css("Height","90");

答案 3 :(得分:0)

试试这个

$('#player').removeAttr('style');
相关问题