javascript-tutorial / javascript-tutorial/en.javascript.info
sync between attributes and properties
- Dominant language
- HTML
- Stars
- 25.5k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
> 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
```javascript
let inp = document.getElementById('search');
inp.setAttribute('value','initialValue');
inp.value === 'initialValue'; //true
inp.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'; // true
inp.setAttribute('value','has no effect on input.value');
inp.value === 'has no effect on input.value'; // false
inp.value === 'cancel all consecutive attempts to sync via setAttribute'; // true
```
[go to the website](https://javascript.info/dom-attributes-and-properties#property-attribute-synchronization)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the linked DOM attributes and properties section, especially the property-attribute synchronization example. Clarify the documented behavior after directly assigning input.value, then update the section if the one-way synchronization caveat belongs there; done means the example accurately explains why later setAttribute calls do not change input.value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100