I have the following page code:
<html>
<body>
<div id="AAA"> SOME CODE </div>
<div>
<iframe>
<html>
<div id="AAA"> SOME CODE </div>
<div id="myDiv"> MORE CODE </div>
</html>
</iframe>
<iframe>
<html>
<div id="AAA"> SOME CODE </div>
<div id="myDiv2"> MORE CODE </div>
</html>
</iframe>
</div>
</body>
</html>
Now, the fun part.
I can put my hands on the div "myDiv". Then I want to modify the content of div "AAA", the one that is in the same iframe.
However if I do
myDiv.ownerDocument.getElementById("AAA")
I get the element outside the iframe – notice there are three elements with id=”AAA”…
My question is, given an element, how can I put my hands on its containing iframe, and not on the most top level document?
Any help is appreciated.
Out of my sleeve, try such function: