Chapter 2. JavaScript in the Browser
Now I'm going to lay the foundation for the rest of this book. Since I'm going to be discussing JavaScript generally as a language but also specifically as a tool for web development, you should understand precisely how it interacts with the browser. This way, when I discuss ideas like the Document Object Model (the DOM) or how JavaScript interacts with HTML in the examples later in this book, you will know exactly what I am talking about.
JavaScript has been around long enough that all the major modern browsers (Internet Explorer, Firefox / Netscape, Opera, Safari, and Chrome) pretty much work the same way when it comes to handling scripts and how they interact with documents. Of course, there are a lot of differences when you get down to the fine details, but in general terms browsers try to act in a consistent way with one another. The general syntax of ECMAScript, the way you embed scripts on a page, and the general structure of DOMs are more or less consistent. This is a good thing, because if it wasn't true, JavaScript development would be very difficult to learn.
The Document Object Model
I've already introduced the idea of the DOM (Document Object Model) in Chapter 1, but now we need to look at its structure in more detail so that you understand how scripts interact with it. The DOM serves as an object representation of all the elements and information pertaining to the layout of the page. Technically speaking, a browser does not need a ...
Get JavaScript® Programmer's Reference 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.