How to do a basic image swap
So far I've explained how to do many things, but I haven't described why they work. In the last lesson, for instance, I showed you that window.document.monkey_image.src = "happy_monkey.gif" will swap happy_monkey.gif into an image named monkey_image. But what is that window.document stuff? And where does the .src come from? Similarly, you've seen document.writeln("monkey"). But why is it document.writeln and not just writeln?
The answer to the above questions can be found in the JavaScript Document Object Model. The DOM is the way JavaScript describes Web pages, and it lies at the heart of all JavaScript programming. This lesson will teach you about the DOM, and the next lesson will teach you the rest of the basics of computer programming. By the end of the next two lessons, you will know all of the major ideas and syntax of JavaScript. All that will be left to learn are details, tricks, and how to avoid snafus.
To start us off along the road to the DOM, let's learn about how to use JavaScript to open and manipulate new browser windows.
next page»