title: Better way of extracting text from HTML in Javascript
body: <p>I'm trying to scrape text from an HTML string by using <code>container.innerText || container.textContent</code> where <code>container</code> is the element from which I want to extract text.</p>
  
  <p>Usually, the text I want to extract is located in <code>&lt;p&gt;</code> tags. So for the HTML below as an example:</p>
  
  <pre><code>&lt;div id="container"&gt;
      &lt;p&gt;This is the first sentence.&lt;/p&gt;
      &lt;p&gt;This is the second sentence.&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Using</p>
  
  <pre><code>var container = document.getElementById("container");
  var text = container.innerText || container.textContent; // the text I want
  </code></pre>
  
  <p>will return <code>This is the first sentence.This is the second sentence.</code> without a space between the first period and the start of the second sentence.</p>
  
  <p>My overall goal is to parse text using the Stanford CoreNLP, but its parser cannot detect that these are 2 sentences because they are not separated by a space. Is there a better way of extracting text from HTML such that the sentences are separated by a space character?</p>
  
  <p>The HTML I'm parsing will have the text I want mostly in <code>&lt;p&gt;</code> tags, but the HTML may also contain <code>&lt;img&gt;</code>, <code>&lt;a&gt;</code>, and other tags embeeded between <code>&lt;p&gt;</code> tags.</p>