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

249
Visualizações
Am having problem with using get element by class name

when i use getElementByClass name it runs from top to bottom of the document therefore selecting elements that are in the upper part of the document before elements in the lower part of the document. So is it possible to change that like maybe instead of getting another html collection it will just update the htmlcollection please look at the code to understand the question enter image description here

enter image description here

const hi = document.getElementsByClassName("hi");
let hey = document.getElementsByClassName("hey");
// it will return an html collection with <p class="hey"> one</p> as the only element
// then if i add hey class to hi
hi.classList.add("hey")
//add i getElementsByClassName("hey")
hey = document.getElementsByClassName("hey");
//then it will return an html collection with 
//  <p class="hi hey"> two </p>  as the first item
// and <p class="hey"> one</p> as the second item

// my question is that is it possible for <p class="hey"> one</p> to be the first item since it
// was the first element to have the class name hey
// and <p class="hi hey"> two </p> to be the second item
<p class="hi">two</p>
    <p class="hey">one</p>

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