How to make string "Review 1" with sequencial white spaces in the middle to be rendered as such. Please see the example below.
<div id="target"></div>
var name = "Review 1"
$('#target').html(name);
Thanks
How to make string "Review 1" with sequencial white spaces in the middle to be rendered as such. Please see the example below.
<div id="target"></div>
var name = "Review 1"
$('#target').html(name);
Thanks
Use one
for every space
Change how white-space is handled:
<div id="target" style="white-space: pre;"></div>
If you need multiple spaces you can use the html encoded character for a space:
(=non break space)
var name = "Review 1"
var name = "Review 1".replace(/ /g, " ");
$('#target').html( name );
You need to use .replace()
Give this a try:
$(function () {
var name = "Review 1"
$('#target').html(name.replace(/\s/g, ' '));
});
Working example: http://jsfiddle.net/t4jtJ/1/
Use
like others have said. If the text is dynamic, use replace:
name = name.replace(/\s/g,' ');
Well you can use <pre>
tag:
$('#target').html('<pre>'+name+'</pre>');
checkout the fiddle: http://jsfiddle.net/8BJuB/