I can\'t figure out how to trigger a keydown event on a textarea element, e.g. imagine i have two textarea elements and when i type something in the first one, I want the se
Try this:
$(document).ready(function() {
var $comment = '';
$('#first').keyup(function() {
$comment = $(this).val();
$comment = $comment.replace(/<\/?[^>]+>/g,"").replace(/\n/g, "
").replace(/\n\n+/g, '
'); // this strips tags and then replaces new lines with breaks
$('#second').html( $comment );
});
});
Working demo: http://jsbin.com/ivulu
Or if you don't want to sanitize the data: http://jsbin.com/oposu
$(document).ready(function() {
var $comment = '';
$('#first').keyup(function() {
$comment = $(this).val();
$('#second').html( $comment );
});
});