Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.text() doesn't work with textarea elements

Any reason why jQuery('textarea').text() always returns default value instead of current text when the text area actually has some text and jQuery('textarea')[0].value does return the text? Take a look at the simple example to see the problem.

like image 890
Andrey Avatar asked Jul 20 '26 12:07

Andrey


1 Answers

Entering a value in an input element (textarea being one of them) doesn't change the markup. text() only grabs the text content of the markup. You should use val() instead:

jQuery('textarea').val()
like image 82
Ates Goral Avatar answered Jul 23 '26 03:07

Ates Goral



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!