Why not use RegExp?

Element.implement({
    removeClassesExcept: function(klass) {
        return this.set("class",new RegExp(klass).exec(this.get("class")));
    }
});

If the RegExp /klass/ matches class, class is "klass", otherwise it's null.
Yann


On Sun, Feb 14, 2010 at 23:32, Dimitar Christoff <[email protected]>wrote:

> > Anyway, this way is just a function around the same basic logic... not
> > really reaching the "cleverer" mark. :)
>
> the 'clever' i could think of  without involving garden gnomes was this:
>
> Element.implement({
>    removeClassesExcept: function(klass) {
>        return this.hasClass(klass) ? this.set("class", klass) :
> this.erase("class");
>    }
> });
>
> http://mootools.net/shell/Wpqum/1/ - tested in FF 2.5 and IE7. back to
> gardening now...
>
> regards,
> --
> Dimitar Christoff <[email protected]> - http://fragged.org/
>
>

Reply via email to