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

108
Visualizações
Substitution of content by js

I have a problem with JS code. Well, the text of the first link changes. The second one stays the same and I would like to change too. How to do it correctly?

HTML:

<h4 class="comments-title">Text1</h4>
        <a rel="nofollow" class="comment-reply-link" href="#comment-25416">reply</a>    

        <a rel="nofollow" class="comment-reply-link" href="#comment-2">reply</a>

JS:

    function podmien(klasa, tekst) {
    document.querySelector(klasa).innerHTML = tekst;
}
document.addEventListener('DOMContentLoaded', function() {
podmien('.comments-title', 'Com');
podmien('.comment-reply-link', 'Answer');
Document.getElementsByClassName
});

https://jsfiddle.net/tomaszpl/8s43wao5/28/

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

0

querySelector will only select the first element. What you need is querySelectorAll to select all elements.

function podmienAll(klasa, tekst) {
  document.querySelectorAll(klasa).forEach(v => {
    v.innerHTML = tekst;
  });
}

document.addEventListener('DOMContentLoaded', function() {
  podmienAll('.comments-title', 'Com');
  podmienAll('.comment-reply-link', 'Answer');
});
<h4 class="comments-title">Text1</h4>
<a rel="nofollow" class="comment-reply-link" href="#comment-25416">reply</a>
<a rel="nofollow" class="comment-reply-link" href="#comment-2">reply</a>

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