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

244
Vistas
.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 Respuestas
Responde la pregunta

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