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

214
Vistas
How can I put a condition on the way of jQuery chain?

I have this function:

function startBlinking(el, speed = 100) {
  el.css('display', 'inline').fadeToggle(speed, function() {
    startBlinking(el, speed)
  });
}

I want to add one more parameter to the function to make .css('display', 'inline') part conditional. Something like this:

function startBlinking(el, speed = 100, inlineDisplay = true) {

  if (inlineDisplay){
      el.css('display', 'inline').fadeToggle(speed, function() {
        startBlinking(el, speed)
      });
  } else {
      el.fadeToggle(speed, function() {
        startBlinking(el, speed)
      });
  }
}

But the new version looks ugly. I want to know is there any approach to add a condition in the chain?

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

0

Get the current display value and add a condition for inlineDisplay parameter. If inlineDisplay is false or undefined the current display value will persist else it will be inline.


function startBlinking(el, speed = 100, inlineDisplay = true) {
    const currentDisplay = el.css('display');
    el.css('display', inlineDisplay ? 'inline' : currentDisplay).fadeToggle(speed, function() {
        startBlinking(el, speed)
      });
}

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