HTML and CSS Reference
In-Depth Information
Figure 15.32 A scrolling marquee continues to print news across the image.
15.8 Event Handling and the DOM
15.8.1 The HTML Inline Way
We have been using event handlers like onClick , onSubmit , onMouseOver , throughout
this text. In fact, Chapter 13, “Handling Events,” described in detail all of the different
event handlers and how to use them. They are the oldest and simplest way that is
browser compatible. The following example uses the onClick handler as an attribute of
the button element. When the user clicks the button, the function movePosition() will
be called.
<input type="button" value="move text"
onClick="movePosition() "/>
But using this type of handler violates the principle of separation of the layers; that
is, the separation of markup from JavaScript.
The Scripting Way
To keep the markup and the JavaScript separate, the JavaScript provided a way for pro-
grammers to apply properties to any object in the HTML tree. In the following example,
the onLoad event property is applied to the window object so that when the document
has completed loading the function assigned to that object will be triggered. In this
example the background color will be changed to light green. See Chapter 13 for details
if you need to be refreshed on this traditional model for handling events.
Search WWH ::

Custom Search