简体   繁体   English

如何添加样式 <iframe> 已知父标记的ID时使用javascript标记?

[英]How to add a style to <iframe> tag using javascript when it's parent tag's id is known?

How to apply a style to an iframe whose parent tag's id is known?? 如何将样式应用于已知其父标签ID的iframe?

Example: 例:

<div id="xyz"> 
 <iframe ....> </iframe>
</div>

I want to apply style to iframe as height: 70px . 我想将样式应用到iframe作为height: 70px I just got to know how to do this using CSS. 我只是知道如何使用CSS来做到这一点。

How can I do that using javascript. 如何使用javascript做到这一点。 Any help very much appreciated! 任何帮助非常感谢!

// grab the div and the first iframe inside it:

var iframe = document.getElementById('xyz').getElementsByTagName('iframe')[0];

// There are two different valid ways to set the height

// 1. Change the attribute like it was <iframe height="70" ... />
iframe.height = '70';

// 2. Change the attribute like it was <iframe style="height: 70px;" ... />
iframe.style.height = '70px';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM