Simple DOM Events

Clicking in the blue box will pop up a "Hello World!" alert window. Clicking on the first link will take you to the YUI website; clicking on the second link, which has the same href attribute, will pop up an alert instead and not navigate to a new page.

Event Utility is used here to do two things:

  1. Attach the click event handler to the blue box;
  2. Attach an event handler to the second <a> element that uses preventDefault() to prevent the link, when clicked, from navigating to a new page.

Click for Hello World alert.

The YUI Library. (Link navigates away from page.)

The YUI Library. (Link's default behavior is suppressed.)