Reputation: 434
I'm trying to copy some html around a page and I wanted to use the jquery html() to do it. It worked well until I wanted to get a value from a user entered text box and the value hadn't copied.
I looked in firebug and the entered data wasn't shown in the value field of the textbox.
How do I get around this?
Upvotes: 0
Views: 1319
Reputation: 37061
It seems that it impossible to get value using html(), use .val() instead
b.t.w if it is important for you to preserve the line breaks in html format you can do the following:
var textareaHtmlVal = $('#text_area_id').val().replace(/\n/gi,'<br />');
Upvotes: 0
Reputation: 10619
I think you are getting confused between jquery .text()
and .val()
functions
.text()
Get the combined text contents of each element in the set of matched elements, including their descendants.
.val()
Get the current value of the first element in the set of matched elements.
Upvotes: 1
Reputation: 1039
check this not sure if you are looking for this ? http://jsfiddle.net/MMJRk/1/
Upvotes: 0
Reputation: 55678
I think you need to use .val()
to do this:
var textareaText = $('#mytextarea').val();
Upvotes: 2