开发者

mootools add an id

Is there a method like toggleClass() 开发者_运维技巧for and ID in mootools?


$("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


Use the Element.set(); method.

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

documentation: mootools docs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜