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

Adding an element with a unique ID

We will inject new blood into our message by adding a new HTML element to the page.

Getting ready

The Element class deals with methods such as inject() and destroy(). There are also classes for String and Number among others. When faced with a need to add an element with a unique ID attribute, we turn to String.uniqueID(). This method uses Date.now() to return a string that will be, invariably, unique.

How to do it...

Note that to make a copy of our existing my_target we use Element.clone().

<script type="text/javascript" src="mootools-1.3.0.js"></script> </head> <body> <form action="javascript:" method="get"> <input type="button" value="Unique Me!"/> </form> <div id="my_target" style="width:150px; height:150px; ...

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