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?
2 Answers
Reset to default 5A 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