I'm trying to take the value from a textarea
and put it inside a pre tag
, and it works ok on chrome and mozilla but on IE8 the entire content stays on one line in the pre tag
jsbin link: http://jsbin.com/uwunug/4/edit
this is the whole thing:
<html><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<script type='text/javascript'>
$(function(){
$('#b1').click(function(){
x = $('textarea').val();
$('#tt').html(htmlEscape(x));
});
});
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
</script>
<textarea cols='50' rows='20'>
</textarea>
<button id='b1'>make code</button>
<pre class="prettyprint" id='tt'>
</pre>
</body>
</html>
I noticed (by replacing \n
to 'enter') the \n
chars go into the pre but they don't produce new line in there