This is very weird. Apparently, I can use both .val() and .text() to manipulate textarea text.
But after I use .val to change the text, I cannot use .text anymore. The converse is not true.
This is leading to some funky bugs. The reason is because a plugin i am using might be using .val to manipulate the text.
Can anyone explain how this works? Thanks!
You have to use
val(), or (better) thevalueproperty of the textarea.text()works initially because the initial value of the textarea is determined by the text node (if any) it contains. You can even initially change thenodeValueordataproperty of this text node and it will update the textarea’s value. However, as soon as either the user has altered the value of the textarea or script has altered thevalueproperty of the textarea, the text node is out of the picture and is no longer bound to the textarea’s value in any way.