• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Handling Events > Event Handlers as JavaScript Methods

12.2. Event Handlers as JavaScript Methods

An event handler is an attribute of an HTML tag. Since HTML elements are also treated as objects in a JavaScript program, there are a number of event methods that can be used to simulate events (see Table 12.2). When an event method is applied to an object, the object to which it refers behaves as though the event has happened; e.g., the click() method behaves like the onClick event, the blur() method behaves like the onBlur event, and so on.[2] The event method is applied to the object with the dot syntax, as are all other methods; e.g., in a JavaScript program you might see something like the following:

[2] Event methods behave as though the event has happened but in themselves do not trigger an event handler. For example, the click() method does not trigger the onClick event handler.

document.test.button1.click(), window.focus()


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint