title: Javascript If URL has subdirectory
body: <p>Trying to think of an elegant way to remove a subdirectory if a URL contains one and havn't come up with anything. Would love your suggestions. My current implementation has usefulness limited to files at the site's root. Need something more flexible.</p>
  
  <p>The other detail is that it needs to be subdirectory agnostic, so no <code>.split('nameOfSubdirectory')</code> business.</p>
  
  <p>To put it in context, I'm using AJAX and am using the target variable to print into the page's url, so I like to make it pretty.</p>
  
  <p>Using the below method, clicking <code>a[href="otherPage.php"]</code> returns <code>otherPage</code>. If I clicked <code>a[href="subPage/differentPage.html"]</code> it would return <code>subPage</code>. No go.</p>
  
  <pre><code>$('a').click(function(e){
  
      var thiis  = $(this),
          href   = thiis.attr('href'),
          target = href.split('/')[1].split('.')[0];
  
      console.log(target);
  
      /* Does stuff */
  });
  </code></pre>