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

152
Vistas
How to replace an HTML element's text with JavaScript when the element doesn't have a class?

Wanted to change the sentence "watch yesterday's broadcast" to "watch the webinar now"

Wanted to change the sentence "watch yesterday's broadcast" to "watch the webinar now"

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

What about selecting it by using its DOM order?

var perent = document.querySelector("select");
var element = parent.querySelectorAll("option")[1];
element.innerHTML = "watch the webinar now";

This article can help: How to get the child element of a parent using JavaScript?

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use querySelector to get an specific child inside an element and change it.

Snippet

In this case I use querySelector(':nth-child(2)') to get the second child.

var parent = document.querySelector(".someClassName");

console.log(
  parent.querySelector(':nth-child(2)').text
)

document.getElementById('btn').addEventListener('click', () => {
  parent.querySelector(':nth-child(2)').text = 'asdasd asdasd';
})
<button id='btn'>change</button>

<select class="someClassName">
  <option>aker including versions of Lorem Ipsum</option>
  <option>Donec semper tortor ac velit tempus,</option>
  <option>vel pellentesque lorem gravida</option>
</select>

about 4 years ago · Juan Pablo Isaza Denunciar

0

To change the text of the second option

document.getElementsByTagName('select')[0].options[1].innerHTML = "watch the webinar now";

If the option is not always second, you can give the option a id then use that in your query selector.

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