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

Working with the $() and $$() functions


The $() and $$() functions are the bread and butter of MooTools. When you're working with unobtrusive JavaScript, you need to specify which elements you want to operate on.

The dollar and dollars functions help you do just that, they will allow you to specify what elements you want to work on.

Note

Notice, the dollar sign $ is shaped like an S, which we can interpret to mean 'select'.

The $() dollar function

The dollar function is used for getting an element by its ID, which returns a single element that is extended with MooTools Element methods or null if nothing matches. Let's go back to awesomeParagraph in the earlier example. If I wanted to select awesomeParagraph, this is what I would write:

$('awesomeParagraph')

By doing so, we can now operate on it by passing methods to the selection. For example, if you wanted to change its style to have a color of red, you can use the .setStyle() method which allows you to specify a CSS property and its matching...