title: jQuery change title dynamically
body: <p>I am creating just a static html website that got a little large so I started breaking it up into templates. I am including a header.php and have run into a problem with the title. I want to get the name of the page, i.e. about.php and output that in the title <code>&lt;title&gt;Company name - About&lt;/title&gt;</code></p>
  
  <p>I have gotten this working like so:</p>
  
  <pre><code>var name = location.pathname.split('/').slice(-1)[0];
  var title = name.slice(0, -4);
  var finalTitle = "Company-" + title;
  $(document).attr("title", finalTitle);
  </code></pre>
  
  <p>works perfect except for index where it doesn't display the name for obvious reasons. I tried writing an if statement along the lines of:</p>
  
  <pre><code>var name;
  if (location.pathname.split('/').slice(-1)[0] === ""){
     name = "Home";
  } else {
     name = location.pathname.split('/').slice(-1)[0];
  }
  </code></pre>
  
  <p>Now I am not too sure why this isn't working.</p>