开发者

Why do it get parent.childElementCount as undefined

开发者 https://www.devze.com 2023-01-29 21:52 出处:网络
I am teaching myself some Javascript and don\'t understand why Chrome console tells me this when I try it out at the Google homepage:

I am teaching myself some Javascript and don't understand why Chrome console tells me this when I try it out at the Google homepage:

parent
> DOMWindow
parent.childNodes
> undefined
parent.frames[0].childElementCount
> undefined
parent.frames.length
> 1
parent.frames[0].name
> "wgjf"
parent.wgjf.childElementCount
> undefined
parent.frames[0].childElementCount
> undefined
parent.childElementCount
> undefined

I do notice that there are frames, and the parent has child nodes, so why all these u开发者_C百科ndefined?

I would like to teach myself to the point that I can figure out how clicking on a username in the gmail chat window on the left opens up a chat window on the right - I should be able to trace the list of function calls that makes this happen


childNodes is a property of DOM-nodes, a window-object is not a DOM-Node.

Try:

parent //window-object
.document //document-object
.documentElement //root-node, usually <html>
.childNodes // usually <head> and <body>

like suggested by casablanca.

(should return 2 for a valid HTML-document)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号