55
66= The Document Object Model =
77
8- (((drawing)))(((parsing)))When you open a web page in your browser, it
8+ (((drawing)))(((parsing)))When you open a web page in your browser, the browser
99retrieves the page's ((HTML)) text and parses it, much like the way
1010our parser from link:11_language.html#parsing[Chapter 11] parsed
1111programs. The browser builds up a model of the document's
@@ -21,7 +21,7 @@ updated to reflect the changes.
2121
2222You can imagine an ((HTML)) document as a nested set of ((box))es.
2323Tags such as `<body>` and `</body>` enclose other ((tag))s, which in
24- turn contain other tags, or ((text)). Here's the example document from
24+ turn contain other tags or ((text)). Here's the example document from
2525the link:12_browser.html#browser[previous chapter]:
2626
2727[sandbox="homepage"]
@@ -65,8 +65,8 @@ representing the `<html>` tag. It also provides the properties `head` and
6565link:11_language.html#parsing[Chapter 11] for a moment. Their
6666structures are strikingly similar to the structure of a browser's
6767document. Each _((node))_ may refer to other nodes, _children_, which
68- may have their own children. This shape is typical of nested
69- structures where elements can contain subelements that are similar to
68+ in turn may have their own children. This shape is typical of nested
69+ structures where elements can contain sub-elements that are similar to
7070themselves.
7171
7272(((documentElement property)))We call a data structure a _((tree))_
@@ -101,7 +101,7 @@ has a `nodeType` property, which contains a numeric code that
101101identifies the type of node. Regular elements have the value 1, which
102102is also defined as the constant property `document.ELEMENT_NODE`. Text
103103nodes, representing a section of text in the document, have the value
104- 3 (`document.TEXT_NODE`). Comments get the value 8
104+ 3 (`document.TEXT_NODE`). Comments have the value 8
105105(`document.COMMENT_NODE`).
106106
107107So another way to visualize our document ((tree)) is as follows:
@@ -175,8 +175,8 @@ before or after the node itself. For a first child, `previousSibling`
175175will be null, and for a last child, `nextSibling` will be null.
176176
177177(((talksAbout function)))(((recursion)))(((nesting,of objects)))When
178- dealing with a nested data structure like this, recursive functions
179- are often useful. The following one scans a document for ((text node))s
178+ dealing with a nested data structure like this one , recursive functions
179+ are often useful. The following recursive function scans a document for ((text node))s
180180containing a given string and returns `true` when it has found one:
181181
182182[[talksAbout]]
@@ -435,7 +435,7 @@ attributes.
435435
436436(((programming language)))(((syntax highlighting example)))As a simple
437437example, we'll write a “syntax highlighter” that looks for `<pre>`
438- tags (“preformatted”, used for code and similar plain text ) with a
438+ tags (“preformatted”, used for code and similar plaintext ) with a
439439`data-language` attribute and crudely tries to highlight the
440440((keyword))s for that language.
441441
@@ -587,7 +587,7 @@ the precise position of an element on the screen is the
587587`getBoundingClientRect` method. It returns an object with `top`,
588588`bottom`, `left`, and `right` properties, indicating the pixel
589589positions of the sides of the element relative to the top left of the
590- _screen_ . If you want them relative to the whole document, you must
590+ screen . If you want them relative to the whole document, you must
591591add the current scroll position, found under the global `pageXOffset`
592592and `pageYOffset` variables.
593593
@@ -675,11 +675,11 @@ endif::book_target[]
675675style attribute may contain one or more _((declaration))s_, which are
676676a property (such as `color`) followed by a colon and a value (such as
677677`green`). When there is more than one declaration, they must be
678- separated by ((semicolon))s, as in “++ color: red; border: none++” .
678+ separated by ((semicolon))s, as in `" color: red; border: none"` .
679679
680680(((display (CSS))))(((layout)))There are a lot of aspects that can be
681- influenced with styling. For example, the `display` property controls
682- whether an element is displayed as a block or inline element.
681+ influenced by styling. For example, the `display` property controls
682+ whether an element is displayed as a block or an inline element.
683683
684684[source,text/html]
685685----
@@ -731,9 +731,9 @@ letters that follow them capitalized (`style.fontFamily`).
731731== Cascading styles ==
732732
733733indexsee:[Cascading Style Sheets,CSS]
734- (((rule (CSS))))(((style (HTML tag))))The styling system for HTML is called ((CSS)),
734+ (((rule (CSS))))(((style (HTML tag))))The styling system for HTML is called ((CSS))
735735for _Cascading Style Sheets_. A _((style sheet))_ is a set of
736- rules for how to style elements in the document. It can be given
736+ rules for how to style elements in a document. It can be given
737737inside a `<style>` tag.
738738
739739[source,text/html]
@@ -748,7 +748,7 @@ inside a `<style>` tag.
748748----
749749
750750(((rule (CSS))))(((font-weight (CSS))))(((overlay)))The _((cascading))_ in the name
751- refers to the fact that multiple such rules get combined to
751+ refers to the fact that multiple such rules are combined to
752752produce the final style for an element. In the previous example, the
753753default styling for `<strong>` tags, which gives them `font-weight:
754754bold`, is overlaid by the rule in the `<style>` tag, which adds
@@ -766,7 +766,7 @@ precedence and always win.
766766to target things other than ((tag)) names in CSS rules. A rule for
767767`.abc` applies to all elements with `"abc"` in their class attributes.
768768A rule for `#xyz` applies to the element with an `id` attribute of
769- `"xyz"` (which should be unique, within the document).
769+ `"xyz"` (which should be unique within the document).
770770
771771[source,text/css]
772772----
@@ -850,20 +850,19 @@ element or null if no elements match.
850850[[animation]]
851851== Positioning and animating ==
852852
853- (((position (CSS))))The `position` style property influences layout in
854- a powerful way.
855-
856- (((relative positioning)))(((top (CSS))))(((left (CSS))))(((absolute
857- positioning)))By default it has a value of `static`, meaning the
858- element sits in its normal place in the document. When it is set to
859- `relative`, the element still takes up space in the document, but now
860- the `top` and `left` style properties can be used to move it relative
861- to its normal place. When `position` is set to `absolute`, the element
862- is removed from the normal document flow—that is, it no longer takes
863- up space and may overlap with other elements. Also, its `top` and `left`
864- properties can be used to absolutely position it relative to the top-left
865- corner of the nearest enclosing element whose `position` property
866- isn't `static`, or relative to the document if no such enclosing element exists.
853+ (((position (CSS))))(((relative positioning)))(((top (CSS))))(((left
854+ (CSS))))(((absolute positioning)))The `position` style property
855+ influences layout in a powerful way. By default it has a value of
856+ `static`, meaning the element sits in its normal place in the
857+ document. When it is set to `relative`, the element still takes up
858+ space in the document, but now the `top` and `left` style properties
859+ can be used to move it relative to its normal place. When `position`
860+ is set to `absolute`, the element is removed from the normal document
861+ flow—that is, it no longer takes up space and may overlap with other
862+ elements. Also, its `top` and `left` properties can be used to
863+ absolutely position it relative to the top-left corner of the nearest
864+ enclosing element whose `position` property isn't `static`, or
865+ relative to the document if no such enclosing element exists.
867866
868867We can use this to create an ((animation)). The following document
869868displays a picture of a cat that floats around in an ((ellipse)):
@@ -939,9 +938,9 @@ finding points that lie on a circle around point (0,0) with a radius
939938of one unit. Both functions interpret their argument as the position
940939on this circle, with zero denoting the point on the far right of the
941940circle, going clockwise until 2π (about 6.28) has taken us around the
942- whole circle. `Math.cos` tells you the x coordinate of the point that
941+ whole circle. `Math.cos` tells you the x- coordinate of the point that
943942corresponds to the given position around the circle, while `Math.sin`
944- yields the y coordinate. Positions (or angles) greater than 2π or less than
943+ yields the y- coordinate. Positions (or angles) greater than 2π or less than
9459440 are valid—the rotation repeats so that _a_+2π refers to the same
946945((angle)) as _a_.
947946
@@ -963,7 +962,7 @@ we have to append `"px"` to the number to tell the browser we are
963962counting in ((pixel))s (as opposed to centimeters, “ems”, or other
964963units). This is easy to forget. Using numbers without units will
965964result in your style being ignored—unless the number is 0, which
966- always means the same, regardless of its unit.
965+ always means the same thing , regardless of its unit.
967966
968967== Summary ==
969968
@@ -989,7 +988,7 @@ element's style directly through its `style` property.
989988[[exercise_table]]
990989=== Build a table ===
991990
992- (((table (HTML tag))))We built plain-text ((table))s in
991+ (((table (HTML tag))))We built plaintext ((table))s in
993992link:06_object.html#tables[Chapter 6]. HTML makes laying out tables
994993quite a bit easier. An ((HTML)) table is built with the following tag
995994structure:
0 commit comments