Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

to check if a url contains any string, do the following:

if(window.location.href.indexOf(".com/poste") > -1) {
       // do something
}

(checking if the index of a string is bigger than -1 is like asking if he is in there)

to conditonally add class:

element.classList.add("my-class");

combined it would be:

if(window.location.href.indexOf(".com/poste") > -1) {
       titleClass = document.querySelector(".your-title-class");
       titleClass.classList.add("conditionalClass");
}

*there are other solutions using jquery (like the one in @Wimanicesir comment), but it personaly prefer not using it :)

about 4 years ago · Juan Pablo Isaza Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda