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

212
Visualizações
Use XPath to select all values on a page and replace content

I want to replace every instance of the word "Specialization" with "Profession." This is the XPath code I have so far:

<script type="text/javascript">

var xpath = "//div[text()='Specialization']"; 
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
matchingElement.style.color = "red";

</script>

My thanks to @Mateen for their help with my original question for writing the above line for me in the first place.

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

0

Not sure why you need an XPath solution, but if you want to stick with the standard DOM API, here's a simple solution.

document.querySelectorAll("div").forEach(function(d){
  if(d.textContent.includes("Foo")){
    d.textContent = d.textContent.replace("Foo","FooBar");
    d.classList.add("match");
  }
});
.match { color:#f00; }
<div>Foo is cool</div>
<div>Bar is not</div>
<div>Foo is cool</div>
<div>Bar is not</div>
<div>Foo is cool</div>
<div>Bar is not</div>
<div>Foo is cool</div>
<div>Bar is not</div>
<div>Foo is cool</div>
<div>Bar is not</div>
<div>Foo is cool</div>
<div>Bar is not</div>

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