I am attempting to get an element by id. The problem I am running into is working with a complex DOM. I understand I can get a element by id. document.getElementById('#some-id')
The DOM that I am working with seems to have an two inner DOMs
. My question is how do I get an ID from an inner DOM
. I have attached a screen shot as shown below to demostrate what I am working with as you can see from the screen shot there are two document objects and the root document object is what I am currently receiving when printing out the contents of the document
object.
How do you get an element that exists embedded within another DOM
.
<!--Root DOM-->
<!DOCTYPE html>
<!--Creates dom object-->
<iframe id="i1" src="iframe1.html">
<!--Creates dom object-->
<iframe id="i2" src="iframe2.html">
<!--How do you access this element by id.-->
<div id="flyover">
innerHtml
</div>
</iframe>
</iframe>
Technically, you're correct - the iframe
will host its own DOM.
You have to traverse the outer DOMs into the sub-frame you're attempting to perform operations on:
window.frames[0].frames[0].document.getElementById("flyout");
您可以通过在iframe
添加一个id
来实现此目的,而不是使用:
document.getElementById( /* your ID */ ).contentWindow.document.getElementById("flyout");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.