title: Get root domain from location.host
body: <p>There are a lot of SO questions that seem to address variations of this question. But they tend to be complex regex answers and I am hoping I can find something simpler. </p>
  
  <p>Given location.host values of</p>
  
  <pre><code>foo.mysite.com
  app.foo.mysite.com
  mysite.com
  </code></pre>
  
  <p>How can I get the root domain <code>mysite.com</code>? </p>
  
  <p>I could do something like finding the second to last <code>.</code>, but this seems ugly and wouldn't work for any TLD's like <code>.co.uk</code>. If jQuery has an object that contains this information I am happy to use it.</p>
  
  <p>My goal is to create cookies that exist across all subdomains. To do this I need to find <code>.mysite.com</code>. I'd prefer not to hardcode it.</p>