The .val()
function gets the "value" attribute of the <textarea>
element, while .text()
gets the contents of the text nodes (node type 3) in the element. I'd say that if setting .text()
works at all, it's not a good idea, as it's essentially fooling around with the basic building blocks of matter. It could cause a bug, or a browser crash, or a devastating explosion.
Use .val()
.
edit — .text()
works up to the point at which a user interacts with the <textarea>
element, or JavaScript code sets the "value" property. After that point, the DOM content of the element becomes irrelevant. You can still get it, but it won't reflect the actual state of the element.