R
RobG
I was messing with get/setAttributeNode to set an element's value and
it seems that all of the following are W3C DOM 2 Core compliant:
el.getAttributeNode('value').value = newValue;
and
var attNode = document.createAttribute('value');
attNode.value = newValue;
el.setAttributeNode(attNode);
and
var attNode = el.getAttributeNode('value');
attNode.value = newValue;
el.setAttributeNode(attNode);
For the last one, IE 6 shows an error but successfully changes the
attribute value.
Is there any reason to prefer the second or third over the first?
Using getAttributeNode to set values seems a bit strange and makes me
wonder what the purpose of setAttributeNode is (other than
completeness). But if it's OK to use then I'll do that because it's
much more concise.
it seems that all of the following are W3C DOM 2 Core compliant:
el.getAttributeNode('value').value = newValue;
and
var attNode = document.createAttribute('value');
attNode.value = newValue;
el.setAttributeNode(attNode);
and
var attNode = el.getAttributeNode('value');
attNode.value = newValue;
el.setAttributeNode(attNode);
For the last one, IE 6 shows an error but successfully changes the
attribute value.
Is there any reason to prefer the second or third over the first?
Using getAttributeNode to set values seems a bit strange and makes me
wonder what the purpose of setAttributeNode is (other than
completeness). But if it's OK to use then I'll do that because it's
much more concise.