最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to remove an attribute with PrototypeJS - Stack Overflow

programmeradmin3浏览0评论

The only thing I'm seeing from google searches is that

Element.writeAttribute() - Adds, specifies or removes attributes passed as either a hash or a name/value pair.

However, the only examples I see is adding/modifying and attribute/value, not removing.

Say that I have html element

<input id="chk" type="checkbox" class="myclass" checked="checked" />

How would I remove the checked attribute using PrototypeJS?

The only thing I'm seeing from google searches is that

Element.writeAttribute() - Adds, specifies or removes attributes passed as either a hash or a name/value pair.

However, the only examples I see is adding/modifying and attribute/value, not removing.

Say that I have html element

<input id="chk" type="checkbox" class="myclass" checked="checked" />

How would I remove the checked attribute using PrototypeJS?

Share asked Jul 23, 2014 at 20:55 Nick RolandoNick Rolando 26.2k13 gold badges84 silver badges120 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

A quick look at the source code shows:

function writeAttribute(element, name, value) {
  …
  if (value === false || value === null)
    element.removeAttribute(name);
  …
}

So just calling it like this should do the trick:

$("chk").writeAttribute("checked", false);

Demonstration

You also can use vanilla JS and the element.removeAttribute() method... though it isn't Prototype

发布评论

评论列表(0)

  1. 暂无评论