title: Get some string before the space, and save it in a variable with Javascript
body: <p>How can I get "John" from the string "John Smith"?</p>
  
  <p>(I don't want to use .substring(); because its on a contact form and the value could vary.)</p>
  
  <p>Basically I need to get everything before the first space. ;)</p>
  
  <pre><code>   &lt;h1 id="name"&gt;John Smith&lt;/h1&gt;
  
  &lt;script&gt;
  
      var str = document.getElementById("name");
  
      var first = str.split(" ")[0];
  
      alert(first);
  
  &lt;/script&gt;
  </code></pre>