Zero4 Zero4 - 10 months ago 41
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?


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';