Search code examples
javascriptjquerytextareapreview

Jquery: textarea preview (simple and small script)


Simple way to make a preview of a textarea? the code i have below wont format <em>i'm italic!</em> into italics. I'm not very good at js/jquery, and i don't know if the .replace() part is what i need to focus on or what. I've googled it and searched here and couldn't find a simple answer.

$('.comment-block textarea').bind('blur keyup',function() {
    $('#comment-preview').text($('#comment-field').val());
    $('#comment-preview').html($('#comment-preview').html().replace(/\n/g,'<br />'))
});

Solution

  • $('#comment-preview').html($('#comment-field').val().replace(/\n/g,'<br />')); 
    

    doesnt that cut it?