Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync between attributes and properties #1579

Open
dagolinuxoid opened this issue Nov 5, 2019 · 4 comments
Open

sync between attributes and properties #1579

dagolinuxoid opened this issue Nov 5, 2019 · 4 comments

Comments

@dagolinuxoid
Copy link
Contributor

dagolinuxoid commented Nov 5, 2019

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

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

@iliakan
Copy link
Member

iliakan commented Dec 1, 2019

You give so many code lines =)

What you'd like to add? There's a note about syncing properties that it happens one way sometimes.

@dagolinuxoid
Copy link
Contributor Author

Probably it's best to keep it as it is. I just wanted to say that:

after changing a property, further manipulation on a corresponding attribute has no effect on the property.

@iliakan
Copy link
Member

iliakan commented Dec 7, 2019

Are you sure? Is that in the spec?

@dagolinuxoid
Copy link
Contributor Author

It's just my observation. I hope it is more clear than my previous example.

let's say we have the html

<input id='field' value='initial'/>

And the js

const field = document.getElementById('field');
console.log(field.value); // initial

// there is no sync here: I only change a value property, value attr is still intact
field.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 property
console.log(field.value);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants