You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But there are exclusions, for instance input.value synchronizes only from attribute → to property, but not back:
I don't know is it worth or not to mention (as a side note) that the sync between attributes and properties is not going to happen after a property is assigned directly. Example
letinp=document.getElementById('search');inp.setAttribute('value','initialValue');inp.value==='initialValue';//trueinp.setAttribute('value','changedValue via setAttribute');inp.value==='changedValue via setAttribute';// true;inp.value='cancel all consecutive attempts to sync via setAttribute';inp.value==='cancel all consecutive attempts to sync via setAttribute';// trueinp.setAttribute('value','has no effect on input.value');inp.value==='has no effect on input.value';// falseinp.value==='cancel all consecutive attempts to sync via setAttribute';// true
It's just my observation. I hope it is more clear than my previous example.
let's say we have the html
<inputid='field' value='initial'/>
And the js
constfield=document.getElementById('field');console.log(field.value);// initial// there is no sync here: I only change a value property, value attr is still intactfield.value='further altering a value attr has no effect on the value property';console.log(field.getAttribute('value'));// 'initial'field.setAttribute('value',"I can't change the value property by setting a value attr")// further altering a value attr has no effect on the value propertyconsole.log(field.value);
I don't know is it worth or not to mention (as a side note) that the sync between attributes and properties is not going to happen after a property is assigned directly. Example
go to the website
The text was updated successfully, but these errors were encountered: