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

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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