Posted By

robnilas on 01/21/17


Tagged

kajabi jquery


Versions (?)

Add A Class to Body


 / Published in: JavaScript
 

  1. <script>
  2. $(document).ready(function() {
  3.  
  4. var pathname = window.location.pathname;
  5. var pathSlashesReplaced = pathname.replace(/\//g, "-");
  6. var pathSlashesReplacedNoFirstDash = pathSlashesReplaced.replace("-","");
  7. var newClass = pathSlashesReplacedNoFirstDash.replace(/(\.[\s\S]+)/ig, "");
  8.  
  9. $("body").addClass(newClass);
  10. if ( $("body").attr("class") == "")
  11. {
  12. $("body").addClass("class");
  13. }
  14. });
  15. </script>

Report this snippet  

You need to login to post a comment.