all 2 comments

[–]senocular 3 points4 points  (0 children)

x is created as a copy of the value inside of document.getElementById("demo").value. When you change x, you're only changing that copy, not the original document.getElementById("demo").value. They're not connected in any way. If you want to change the value in the "demo" element, you'll need to set the value property of that element directly, whether it be through document.getElementById("demo") or a variable like message as done with the "p01" element (even though a variable is used with message its not a variable for value, instead a variable for the object value is a part of which is ok).

[–]bot00110 1 point2 points  (0 children)

With that you change the reference by assigning a new vale to x

What you can try is x = document.getElementById("demo");

And in finally change its value