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

113
Visualizações
How to assign the variables of an array to elements in querySelectorall [Pure Javascript]

I am trying to assign the values of an array to elements that were selected by the querySelectorAll function, Any help is appreciated. The code I am trying to write that when the viewpoint of the browser is below 768px, the text changes to the ones in the array, I have tried all the methods I could think of

var newb = document.querySelectorAll("#buttonsize button")
var arSizes = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"]
    for(var i = 0; i < arSizes.length; i++) {
      newb[i].textContent = arSizes[i]
   }

It gives this error

Uncaught TypeError: Cannot set properties of undefined (setting 'textContent')

I also tried doing newb.textContent and also using a forEach function.

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

0

I think you haven't enough buttons in html so better listing or buttons firstly

var newb = document.querySelectorAll("#buttonsize button");
var arSizes = ["Small", "Medium", "Large", "X-Large", "Large", "XX-Large"];

Array.from(newb).forEach((btnEl, index) => {
  btnEl.textContent = arSizes[index]
});
<div id="buttonsize">
  <button>1</button>
  <button>2</button>
  <button>3</button>
  <button>4</button>
  <button>5</button>
  <button>6</button>
</div>

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