I came across with this issue way after I completed the website since I had to implement history in ajax based page (which requires to update certain places with html (which
It uses the underlying native element.value = 'someValue'
that of course sets the value property of the element
element.property_to_set = 'new_value';
so it does not change the attribute, that would be
element.setAttribute('value', 'someValue')
which is what attr()
does internally, while prop()
changes the property, just like val()
.
The reason it changes the property, is that the property is what is used in a form submit, and it's normally what is used to get the value back in javascript as well, so it makes sense to stick with the property and not the attribute, as the attribute is normally just used to set the initial value of the property, and changing the attribute later with javascript does not update the property, which would be the opposite problem of the one you're having, and it would affect all form submits and be a major issue.