views:

42

answers:

2

I get a textarea with a keyup function attached. When the user type something, I want this text to be rendered inside the blockquote tag. It works, but id doesn't take the newline and spaces. Can you helpe me?

$('#post_body').keyup(function() {    
$('blockquote').find('span').text($(this).val());
+2  A: 

It does take a newline, however those are usually ignored when rendering HTML. However, you can give that <span> (or the <blockquote>) newline rendering to match by setting it's white-sapce to be the same as a <pre> element, like this:

blockquote span { white-space: pre; }​
//or..
blockquote { white-space: pre; }​

You can test it out here.

Nick Craver
Perfect. Ultra rapid..google indexed this answer in 2 seconds!! Impressive
framomo86
Oh oh. Another problem: This time blocquote text never goes in new line if I don't press "enter" key. It doesnt know that the width is over and overflowing characters remain hidden. Ideas?
framomo86
Ok I solved. I set white-space: pre-wrap
framomo86
A: 

A raw solution would be to replace all newlines with <br/>; tag and all spaces with &amp;nbsp;

Nands