I've read somewhere in a documentation that most browsers don't update DOM as form values change, because frequent DOM manipulation need heavy computing performance. Instead, they create a cache of form values to register form manipulation, and only update the DOM when a the form is submitted.
Do browsers really work this way? Is there an extensive documentation about this behavior?
DOM elements have properties and attributes.
If you change an attribute e.g. the
value=""
then the DOM is changed.But the current
value
of a form element is stored in the propertyvalue
and this is the one that is changed when the user types something e.g. into an input field.If the attribute changes the css rules needs to be rechecked if some don't apply anymore or some others will apply now.
Here a little example:
CSS
HTML
JS
Live Demo (JSFiddle)
If you try this in current FireFox or Chrome and type
bar
or click onprop-change
the color is not changing to green.But if you click on
attr-change
it turns green because the attribute changes.Additionally if you reload and type e.g.
test
into it and then pressattr-change
you see that it will turn green buttest
will still be the current value.