\n\n
answer right on.
\n\nchrome displays attributes, so this led to my confusion.
\n","author":{"@type":"Person","name":"cc young"},"upvoteCount":3,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\n\n\nIn javascript, is what is the difference between setting an HTMLElement property with assignment as versus using setAttribute()
\n
It depends on the property.
\n\nThe value property reflects the current value, the value attribute reflects the default value.
\n\nSome properties map directly onto attributes.
\n","author":{"@type":"Person","name":"Quentin"},"upvoteCount":7}}}Reputation: 20245
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.
Upvotes: 3
Views: 1838
Reputation: 944320
In javascript, is what is the difference between setting an HTMLElement property with assignment as versus using setAttribute()
It depends on the property.
The value property reflects the current value, the value attribute reflects the default value.
Some properties map directly onto attributes.
Upvotes: 7