Zero4 Zero4 - 1 year ago 93
HTML Question

javascript - access iframe's elements

I need to change the style of my frame element, however the iframe has no id or class or name

<div id="A">
<iframe src="iframe-left.html">
<div class="login" style="display : none;"> </div>
<div id="B">
<iframe src="iframe-right.html">
<button onclick = "execute()">Submit</button>

function execute()
parent.document.getElementsByTagName("iframe").contentDocument.querySelector(".login").style.display = 'block';

What's the mistake in the javascript function?

Answer Source

Hi I think you have to get the first element of the node list, see

In other words you have to do:

parent.document.getElementsByTagName("iframe")[0].contentDocument.querySelector(".login").style.display = 'none';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download