First, we should explain why you'd use the style
object when writing Dynamic HTML script code…
Any HTML page element that can take a style property has a corresponding style
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 color
property of the list item's style
object. Curious about the size of the heading elements on the page? Read from each heading's style.fontsize
property. Need to move an element after the page has been loaded and displayed? Use the top
and left
properties of that element's style
object. You get the idea, and you'll surely be seeing many examples using the style object throughout the rest of this book.