'Add a class to a page element contained in a particular url

I want to create a class for the title bars of pages that contain a certain piece of url. My url is www.domainname.com/poste/XXX and I want to add the class only if the part after the .com contains only /poste/. I've seen examples for "contains this term" but it's not exactly what I'm looking for. The existing class for the title bar is: .fusion-page-title-bar Thanks in advance for the help and advice!



Solution 1:[1]

If I understand your problem is that you want to check if the URL ends with /poste/.

You can use the string function endsWith().

  var url = window.location.href
  console.log('Current url: ', url)
  
  if (url.endsWith("js")) {
    console.log('The url ends with js');
  }

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wimanicesir