开发者

mootools add an id

开发者 https://www.devze.com 2023-01-01 04:48 出处:网络
Is there a method like toggleClass() 开发者_运维技巧for and ID in mootools?$(\"someid\").toggleClass(\"selectedState\"); // add or take away .selectedState to an element

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

精彩评论

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