views:

29

answers:

2

Is there a method like toggleClass() for and ID in mootools?

+2  A: 

Use the Element.set(); method.

$('elementID').set('id', 'newId');

documentation: mootools docs

Johrn
+1 - Factoring the title in this is probably what the OP wants, I was thrown by how such an unrelated method got into the question heh.
Nick Craver
+1  A: 

$("someid").toggleClass("selectedState"); // add or take away .selectedState to an element

but there is no native .toggleId, or am I not reading this question right. As suggested, use .set("id") or code your own function. if your objective here is to have, say:

formelement.getElement("input[type=submit]").toggleID("submitter");

it can go like so:

<div class="foo">foo</div>

...

Element.implement({
    toggleID: function(id) {
        return this.set("id", (this.get("id") == id) ? "" : id);
    }
});

var el = document.getElement("div.foo");

el.toggleID("foo");
alert(el.get("id")); // foo
el.toggleID("foo");
alert(el.get("id")); // null
Dimitar Christoff