How can I get "John" from the string "John Smith"?
(I don't want to use .substring(); because its on a contact form and the value could vary.)
Basically I need to get everything before the first space. ;)
<h1 id="name">John Smith</h1>
<script>
var str = document.getElementById("name");
var first = str.split(" ")[0];
alert(first);
</script>