Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Current »

Content Freeze

As of July 25th, 2023, there is a content freeze on this page.

This function attaches an event to an object. For example, you can attach a “click” event to a button. The same can be accomplished by assigning the onclick property on a button; however, with the addEvent() function, you can attach multiple unrelated “click” events to the same object.

Parameters:

  • obj – the object or element to which the event will be applied
  • eventName – the event name. Example: “click”, “mouseover”, etc.
  • func – the event handler function

Examples:

The following code assigns an event to a button.

// get the button object
var myButton = getObj("my_button");

// assign the greeting() function as an event handler
addEvent(myButton, "click", greeting);

function greeting()
{
     alert("Hello There!");
}

Alternatively, an anonymous function can be used when assigning the event.

// get the button object
var myButton = getObj("my_button");

// assign anonymous function as an event handler
addEvent(myButton, "click", function ()
{
     alert("Hello There!");
});
  • No labels