In javascript, is what is the difference between setting an HTMLElement property with assignment as versus using setAttribute(). The following is from a chrome session, leading me to believe there is a difference:
> i = document.createElement('input');
<input>
> i.value = 'abc';
"abc"
> i
<input>
> i.setAttribute('value','abc');
undefined
> i
<input value="abc">
What exactly is the difference? Is it the type of thing that bytes you in the ass?
answer right on.
chrome displays attributes, so this led to my confusion.
undefined" here is merely that that is what element.setAttribute() returns as a value. The line abovei.value = 'abc';prints"abc"simply because that is the value of the assignment expression. Neither output has anything to do with what actually happened to the DOM.