I know how to populate a textarea, but how to populate it so that it maintains the line breaks?
e.g
html
<div id="previous_purchases">blah blah blah<br />blah blah</div>
jquery
$('#previous_purchases').click(function(){
var what = $(this).text();
$('#purchased').text(what);
});
All the blah's just rock up in the textarea on one line. Any ideas?
edit: I have been trying with html() instead of text but it produces the same result. I would imagine by using the html() I would end up with a textarea that had '
' but that is not the case... its just all on one line.
Even with this code:
$('#previous_purchases').click(function(){
var what = $(this).html();
$('#purchased').html(what);
});
Try doing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(
function() {
$('#previous_purchases').click(function() {
var what = $(this).html().replace(/<br>/, '\n');
$('#purchased').html(what);
});
});
</script>
</head>
<body>
<div id="previous_purchases">blah blah blah<br />blah blah</div>
<textarea id="purchased" cols="25" rows="10"></textarea>
</body>
</html>
See Attributes/html
Instead of calling text() function you can use html() and path formatted text to it.
$('#previous_purchases').click(function(){
var what = $(this).text();
$('#purchased').html(what);
});
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