0

I have the single input tag and I have wrote following in my chrome console

enter image description here

This result unexpected for me. In book I have read I read that when I change html attibute then corresponding property shoul be changed. But then I shnage property, attribute should not be changed


P.S.
$0 is feature of chrome and point to the selected element. I selected the input tag before script evaluating.

Community
  • 1
  • 1
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

-1

The two strategies you've written have different purposes, and only foo.value = bar changes the DOM element. Using setAttribute just keeps the changes inside the JavaScript environment and doesn't change the DOM.

See this answer for a more detailed explanation: https://stackoverflow.com/a/36581696/1348109

Community
  • 1
  • 1
jackweirdy
  • 5,632
  • 4
  • 24
  • 33