O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding a group of elements by their class attribute

Collections of HTML elements may be handled as a group.

Getting ready

A favorite trick is to turn the option elements of a select on and off. Using various collections of elements, this is a snap in MooTools.

How to do it...

Use ID attributes to affect unique elements: $('my_single_target'), and use class attributes to affect groups of elements: $$('.my_target_class').

<script type="text/javascript" src="mootools-1.3.0.js"></script> </head> <body> <form action="javascript:" method="get"> Choose an Animal:<br/> <select id="animal"> <option value="">Select Animal</option> <option value="cat">Cat</option> <option value="dog">Dog</option> <option value="pig">Pig</option> </select> // some browsers do ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required