Possible Duplicate:
jQuery convert line breaks to br (nl2br equivalent)
Currently I add <BR>
for each evt.which == 13
. Is there a nl2br()
for JavaScript, so I can do away with this evt.which == 13
?
How different is this from php.js
$('#TextArea').keypress(function(evt) {
if (evt.which == 13) {
var range = $('#TextArea').getSelection();
var image_selection = range.text;
$('#TextArea').replaceSelection('<BR>');
$('#TextArea1').html($('#TextArea').val());
}
});
Take a look at nl2br on php.js which seems exactly what you're looking for. Basically, it's:
EDIT:
your example using
nl2br()
may be changed like this:(note that this updates
#TextArea1
on every keypress and doesn't change the value of#TextArea
wich is what I think you're looking for, but I might be misunderstanding)EDIT2:
If you want to get the behaviour of your old function (with inserting
<br/>
s to#TextArea
) do this:Here is a function nl2br in php.js.