What's with All the Dots?

You may wonder why JavaScript refers to my_image as window.document.my_image and not just as my_image. You may also wonder why you would use window .document.my_image.src when you want to change the src of that image. In short, what's with all the dots?

The answer has to do with how your browser looks at your web page.

Figure 4-17 shows the hierarchical organization of a web page as JavaScript understands it—through the Document Object Model (DOM). At the top of the DOM is the window that contains the web page you're view-ing. That window contains the navigator, document, and location objects. Each of these objects has a lot of information in it, and by changing one you can change what happens on your web page.

The dots ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.