Reputation: 1949
When we are trying to get the html of div using the below code it is having all the data except the text which I am entering in the textarea or input field
var mywindow = $(printDiv).html();
mywindow will have all the html except textarea text, radio button values or inputfield.
I have looked into this question but using clone is giving any text at all.
Upvotes: 0
Views: 463
Reputation: 6930
The thing to remember is that .html()
does exactly what it says: it gives you the HTML currently in the DOM within that node. But the thing is, content entered by the user, and more generally the content of HTML input fields, is not a part of the HTML. Entering text into a textarea or checking a checkbox or radio button doesn't change the HTML one bit. It does update the internal memory representations of the individual DOM nodes, but this isn't represented in the HTML.
Whenever you want to get content from an input element on the page, you have to use .val()
instead of .html()
. The .val()
function also does what it says: it gets you the value of the input field.
Upvotes: 2
Reputation: 1695
To get the text in a textarea you have to use .val()
in JQuery. e.g.
var text = $('#textarea_id').val();
console.log(text);
The second line logs it to the console so you can check it works.
Upvotes: 1