HTML
<h3>Original String</h3>
<pre class="original"> Paragraph of text with multiple white spaces before and after. </pre>
<br>
<h3>Trimmed String</h3>
<pre class="trimmed"></pre>
JQuery
$(document).ready(function(){
var myStr = $(".original").text();
var trimStr = $.trim(myStr);
trimStr = trimStr.replace(/[\r\n]+/g, "");
$(".trimmed").html(trimStr);
});
The above code is trimming start and end of paragraph but not between. The output is:
Paragraph of text with multiple white spaces before and after.
I want the output to be
Paragraph of text with multiple white spaces before and after.
Here is my JS Fiddle: https://jsfiddle.net/n5t3cse1
What am I doing wrong? Please suggest. Thanks!
<pre>tag instead of the<p>tag?