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

170
Vistas
Animate element with specific class and CSS properties

I read Jquery: How to check if the element has certain css class/style and have got this working -

if ($(".box").css('display') == 'block')
{
  
    console.log("message  2 - Div with box class exists and css Block exists")


}

I read how to create jquery slide left and right toggle and got this working -

 $(".box").animate({width: "toggle"});

I can't seem to combine the two above together though. These two attempts failed -

   // ($(".box").css('display') == 'block').animate({width: "toggle"});
   // ($(".box").css('display') == 'block').animate({width: "toggle"});


   var datebox = ($(".box").css('display') == 'block')
   datebox.animate({width: "toggle"})
   datebox.animate({width: "toggle"})

Update 1

I tried Cucunber's suggestion and got this error - Uncaught TypeError: ".box".each is not a function

enter image description here

Update 2

I solved the problem highlighted in Update 1 by adding $ to ('.box'), Cucunber updated his answer below based on the issue I faced.

Update 3

I tinkered with Cucunber's solution and eventually solved my problem with this code.

$(".box" ).each(function( index ) {


   if ($(this).css('display') == 'block' ) { 



console.log( index + ": " + $( this ) );
  



   }
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The sentence '$('.box').css('display') == 'block' returns boolean statement. If you know, .animate method should be used with the html element (selector). Try to use something like this:

'$('.box').css('display') == 'block' && $('.box').animate({width: 'toggle'})

combine it with '.each()' and the final result will be:

$('.box').each(function(){ $(this).css('display') == 'block' && $(this).animate({width: 'toggle'}) })
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