title: jQuery add class based on page URL with separate classes
body: <p>I wanted to find a way to extract from the url the classes to be added to the body. I made some attempts but I only managed to get the last piece of the url.
  Do you know how I could do?   </p>
  
  <p>this is what I tried to do with jquery</p>
  
  <pre><code>var dir= window.location.pathname.split('?')[0].split('/').filter(function (i) { return i !== ""}).slice(-1)[0]
  jQuery("body").addClass(dir);
  </code></pre>
  
  <p>this is what i have:</p>
  
  <pre><code> http://www.test.com/news/hello/
  &lt;body class="hello"&gt;&lt;/body&gt;
  
  http://www.test.com/news/
  &lt;body class="news"&gt;&lt;/body&gt;
  </code></pre>
  
  <p>this is what I would like to have </p>
  
  <pre><code> http://www.test.com/news/hello/
      &lt;body class="hello news"&gt;&lt;/body&gt;
  </code></pre>