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

265
Visualizações
Change the Text in HTML with span class using Javascript

I am trying to use a JavaScript function to change the text in an html span using the class name, but is not working. There is an element with the text "My Tasks", and I am trying to write what I thought was going to be an easy JS function to change the text, but cannot figure it out.

console.log('forgot my JavaScript here');
.helpme {
  color: red;
  font-size: 2em;
}
<div class="helpme">I need html here please</div>

Screenshot of part of HTML body

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

0

to help javascript find the element give it an id:

<span id="foobar" class="toolbartitle">My Tasks</span>

then do

document.getElementById("foobar").innerHTML = "New Text!";

Note that using a class to find an element is dangerous because generally classes are not unique whereas ids exist to be unique, though HTML will not stop you from duplicating them.

about 4 years ago · Juan Pablo Isaza Relatório

0

Please keep in mind that using the class you could customize more than one element

Example:

document.querySelector('.your-class').textContent = "Test 2";
<span class="your-class">Test 1</span>

You can find more information about the querySelector attribute here: Document.querySelector()

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