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());
}
});
nl2br
andevt.which == 13
. Reallykeypress
andevt.which == 13
(wich is the event code forEnter Key
) have nothing to do with converting new lines to HTML's<br>
tag. – Bocage