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

240
Visualizações
.get() method failing in Jquery

I am trying to access and style the different objects inside a jQuery object by using .get(); and I have been successful in simply accessing the individual objects but unable to perform operations like adding css or classes to those individual elements. I also tried to use [] to access and style; but access is again a success while I am not being able to style that selected element. Why is this happening?

my script using .get() =>

$(()=>{
  $('button').click(function(event){
    $(".box div").get(1).toggleClass('color');
  });
});
.box{
  font-size: 0px;
  width: min-content;
}

.color{
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: red;
  border: 1px solid white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
  <div></div>
  <div></div>
  <div></div>
</div>

<button>click</button>

TypeError: $(...).get(...).toggleClass is not a function

Why is this message coming? How to resolve this and get specific index element from a jQuery Object?

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

0

i hope this helps you.

$(()=>{
  $('button').click(function(event){
    $(".box div:nth-child(1)").toggleClass('color');
  });
});
.box{
  font-size: 0px;
  width: min-content;
}

.color{
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: red;
  border: 1px solid white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
  <div></div>
  <div></div>
  <div></div>
</div>

<button>click</button>

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