title: How to preserve whitespace when getting text in a variable
body: <p>I'm trying to put text in a variable that preserves the whitespace. First, I receive my text from my database. This is how the text appears on the page as I used the function <code>nl2br()</code> to preserve the enters:</p>
  
  <pre><code>    random text.
      more random text. 
  </code></pre>
  
  <p>I want to get this text in a variable while preserving the whitespace. Because the tags were wrapped in a div tag, what I tried was this:</p>
  
  <pre><code>var body = $("div").text();
  </code></pre>
  
  <p>However, when I console.log var body, the text's space isn't preserved and it comes out like this, without the newline preservation:</p>
  
  <pre><code>random text.    more random text.
  </code></pre>
  
  <p>Is there any way to preserve the whitespace when using variables to get the text of an element?</p>