JS - if URL contains specific string

0 votes
123 views
added Jun 12, 2019 in Javascript by LC Marshal Captain (25,770 points)
window.onload = function() {
  var url = window.location.pathname,
      activePage = url.substring(url.lastIndexOf('/') + 1),
      newsContent = 'content',
      element = document.getElementById(activePage);
  // if(document.body.classList.contains('page-content')){
  //   element.classList.remove("active");
  // }
  // console.log(element);
  if(url.indexOf(newsContent) > -1) {
     //do nothing
  }
  else {
    element.classList.add("active");
  }
};

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...