title: JQuery to add <body> class, need a little more help
body: <p>I have this snippet of code to parse the URL and add a class to the <code>&lt;body&gt;</code>tag of my HTML page. </p>
  
  <pre><code>var pathname = window.location.pathname;
  var pathSlashesReplaced = pathname.replace(/\//g, " ");
  var pathSlashesReplacedNoFirstDash = pathSlashesReplaced.replace(" ","");
  var newClass = pathSlashesReplacedNoFirstDash.replace(/(\.[\s\S]+)/ig, "");
  
  $("body").attr("class",newClass);
  if ( $("body").attr("class") == "")
  {
  $("body").addClass("class");
  }
  </code></pre>
  
  <p>The issue I am having is that it deletes existing body classes already there. Instead, I would like to append to whatever body classes exist and not overwrite. </p>