Prototype.js has a method, Element.identify(), that can be very useful. It is used to retrieve the ID of a given element. If one does not exist it first generates and assigns one and then returns that.
To implement this in MooTools you can add the following code.
Element.implement({
identify: function() {
if(!$type(this.get('id')))
this.set('id', genID(0));
return this.get('id');
function genID(num) {
num++;
if(!$type($(num.toString())))
return num;
return genID(num);
}
}
});