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—selecting multiple sets of elements with the dollars function


What if we wanted to select multiple sets of elements and run the same method (or methods) on them? Let's do that now.

  1. Let's select the list item that has an<a> element inside it and the last list item (class="lastItem"), and then animate them to the right by transitioning their margin-left CSS property using the .tween() method.

  2. Right below the line we wrote previously, place the following line:

    $$('li a, .lastItem').tween('margin-left', '50px');
    
  3. View your work in your web browser. You should see the second and last list item move to the right by 50 pixels.

What just happened?

We explored the dollar and dollars functions to see how to select different elements and apply methods to them. You just learned to select:

  • An element with an ID (#listItem and #superList) using the dollar $() function

  • An element with a class ( .lastItem) using the dollars $$() function

  • Multiple elements by separating them with commas (li...