James Black wrote:
I am curious if there is a benefit to set attributes directly, in my
javascript, or to use setAttribute.
For example, I have this:
var input = document.createElementNS(xhtmlNS, 'input');
input.setAttribute('width', '20em');
I could have just called input.width='20em'
When is each better to use, or is there no difference between them?
Input doesn't have a width attribute, so this isn't a good example. The
first form should throw an exception while the second will add a
property 'width' to 'input'.
For attributes defined in the DOM, you are better off using the second
form. setAttribute doesn't work as expected in IE, which can cause all
kinds of problems (try setting the class of an element with setAttribute).
--
Ian Collins.