With jQuery, I added a textarea
$('#description').append('<textarea rows="8" cols="40">test</textarea>');
Ok, and I change "test" text to "test 01". But, when I try
var cadena = $('#description').text();
alert(cadena);
I get "test" and not "test 01". Why?
give the textarea
an id and then change it's value with the val
function:
$('#description').append('<textarea id="xxx" rows="8" cols="40">test</textarea>');
$('#xxx').val('test01');
//... later on
alert($('#xxx').val());
Like it says on the .text()
doco page, "To set or get the text value of input or textarea elements, use the .val()
method."
You don't say how you change the text, but you should be doing this:
$('#description textarea').val("test 01"); // change the text
var cadena = $('#description textarea').val(); // retrieve the current text
Noting that "#description" is the textarea's container, and you need to select the textarea itself to get the value. Of course the above won't work if you have more than one textarea in that container, so it would be better if you could assign the new textarea an id an then select based on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With