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

85
Visualizações
Replacing getElementById with getElementsByClassName and using innerHTML

Here's my original code:

if (document.getElementById("domain")) {
    document.getElementById("domain").innerHTML = "example.com";
}

I tried updating to this, but it's not working:

if (document.getElementsByClassName("domain")) {
    document.getElementsByClassName("domain").innerHTML = "example.com";
}

It's my understanding that it's not working because getElementsByClassName uses an array. What's the easiest way to make it update the innerHTML across all the elements with that class name? Do I have to loop through the array or is there a simpler method with pure Javascript?

EDIT: I'm making this change because I need to replace the innerHTML multiple times. Before I was just needing to replace a single element.

about 4 years ago · Juan Pablo Isaza
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