Book Image

MooTools 1.2 Beginner's Guide

Book Image

MooTools 1.2 Beginner's Guide

Overview of this book

MooTools is a simple-to-use JavaScript library, ideal for people with basic JavaScript skills who want to elevate their web applications to a superior level. If you're a newcomer to MooTools looking to build dynamic, rich, and user-interactive web site applications this beginner's guide with its easy-to-follow step-by-step instructions is all you need to rapidly get to grips with MooTools.
Table of Contents (14 chapters)
MooTools 1.2 Beginner's Guide
Credits
About the Authors
About the Reviewer
Preface

Time for action—preventing event bubbling


Let's say you have two divs, one inside another. When a div is clicked, it will open up the alert box that displays the div's ID property value.

  1. Let's start with the HTML. In the following HTML markup, we have two div elements. The parent div has an ID of #parent and the child div has an ID of #child.

    <body>
    <div id="parent">
    <p>#parent</p>
    <div id="child">
    <p>#child</p>
    </div>
    </div>
    </body>
    
  2. We'll style them with different background colors, widths, and heights so we can see each div better.

    #parent {
    width:200px;
    height:200px;
    background-color: #999;
    }
    #child {
    width:100px;
    height:100px;
    background-color:#ccc;
    }
    
  3. Open the HTML browser. You should see the following:

  4. Let's explore the concept of event bubbling by adding a click event on all divs in the web page. When the click event is triggered, we will display an alert dialog box with the ID of the div that triggered the event.

    $$('div').addEvent...