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?
this is what I tried to do with jquery
var dir= window.location.pathname.split('?')[0].split('/').filter(function (i) { return i !== ""}).slice(-1)[0]
jQuery("body").addClass(dir);
this is what i have:
http://www.test.com/news/hello/
http://www.test.com/news/
this is what I would like to have
http://www.test.com/news/hello/
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)