The Element.js file in MooTools core handles some attributes in a
custom manner. From a programmatic js perspective, I rarely encounter
a need for the HTML attribute. However, I _have_ encountered such a
need: when I want to reset for values to their original state. In this
case, I use:
this.getElements('option[selected=true]').each(function(o)
{ o.selected = true });
which requires an HTML 'selected' attribute.
You can use this:
document.id('someOptionIDTag').setAttribute('selected', 'selected');
But, that is, er, less than elegant.
The rest of my comments apply to:
https://github.com/mootools/mootools-core/blob/master/Source/Element/Element.js
Starting @ line 540, bools defined boolean attributes (including
'selected') and added a propertySetters function to simply call:
propertySetters[{'selected'}] = function (node, value) {
node[bool] = !!value;
};
This is why you don't see an HTML attribute for the 'selected'
property you are passing.
Element.js could be modified as follows, starting @ line 561, but I'm
not sure if this would break other behavior:
Object.append(propertySetters, {
'class': function (node, value) {
('className' in node) ? node.className = value :
node.setAttribute('class', value);
},
'for': function (node, value) {
('htmlFor' in node) ? node.htmlFor = value :
node.setAttribute('for', value);
},
'style': function (node, value) {
(node.style) ? node.style.cssText = value :
node.setAttribute('style', value);
},
// handle 'selected' in both the javascript and HTML?
'selected': function (node, value) {
node.selected = !!value; // not sure you really need this if you
have the next line(s)
if (value) node.setAttribute('selected', 'selected');
else node.removeProperties('selected');
}
});
I'll defer to others regarding the wisdom of such an override.
Eric