You should remember about the Document Object Model and elements being parents, children, ancestors and descendants.  You have already used that concept in your JavaScript.  For example:

document.getElementById('fred')

The document is the parent/ancestor and one of it's descendants has the id fred.  This is easy and works so you will use this a lot but you can also access items through the DOM structure.

Technically the DOM ultimate parent is window but generally that is left off and assumed so the document becomes the ultimate parent in you code.  The above example should properly look like this:

window.document.getElementById('fred')