Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!