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—rewriting our script unobtrusively


Let's rewrite the previous example to follow unobtrusive JavaScript principles:

  1. First, we'll remove all the onclick attributes. By doing so, we've effectively separated our website's functionality from its content structure. Here's the revised code:

    <html>
    <head>
    <script type="text/javascript">
    function mouseClick()
    {
    alert( 'You clicked me!' );
    }
    </script>
    </head>
    <body>
    <ul id="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
    </ul>
    </body>
    </html>
    
  2. Now remove the mouseClick() function; we don't need it anymore.

    <html>
    <head>
    <!-- mouseClick() function is now bye-bye. -->
    </head>
    <body>
    <ul id="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href...