Is there a method like toggleClass() for and ID in mootools?
+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
2010-05-28 16:31:09
+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
2010-05-29 12:43:34