First, we should explain why you'd use the
object when writing Dynamic HTML script code…style
Any HTML page element that can take a style property has a corresponding
object. This object is of no importance while we're writing the page layout and text itself, but plays a vital role when we come to write code. In short, if we want to do anything to a page element dynamically, we'll use the underlying style
object to do it. Want to change the color of a list item as the mouse moves over it? Write to the style
property of the list item's color
object. Curious about the size of the heading elements on the page? Read from each heading's style
property. Need to move an element after the page has been loaded and displayed? Use the style.fontsize
and top
properties of that element's left
object. You get the idea, and you'll surely be seeing many examples using the style object throughout the rest of this book.style