HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 14. JAVASCRIPT AND AJAX 150


But there are a couple of things that you need to learn. You need to learn
theDOM, and you need to learn Camel Case.


14.4.1 The DOM


TheDOMis the Document Object Model. It is a way of identifying parts
of the webpage so they can be used or changed by a JavaScript program.


Exam Question 264(p.351): What does DOM stand for?
Acceptable Answer:document object model


When a webpage is going to be displayed, it must first be loaded into memory
inside the browser.


This loading process converts the text of the webpage into a memory-only
representation called the DOM. The HTML exists merely to let the browser
use it to create the DOM. The DOM is the real webpage.


The DOM is sometimes referred to as a tree, or as the document tree.


Once the tree is built, the browser uses it to render the page. To render
means to display the page.


The DOM can be modified “on the fly” by using JavaScript. When the DOM
is modified, the browser is required to immediately update the displayed
page so it correctly matches the DOM.


None of these changes affect the original webpage that was presented by the
server. They only affect the webpage that is seen at the browser.


14.4.2 Camel Case


One thing we wish to point out here is the use of Camel Case for naming
the background color attribute.


You may have noticed that with JavaScript backgroundColor was used in-
stead of the CSS version, background-color.


CSS is happy to have dashes inside attribute names. In JavaScript, dashes
mean subtraction.


So, instead of having dashes, the attribute names are pushed together, and
any letter that was after a dash gets changed to uppercase. The rest are
lowercase.

Free download pdf