Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda