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

198
Views
How do I optimize the code so that I don't have to write a new number every time?

I have js code like this:

 lightGallery($("#web1")[0], {
    selector: 'this',
    mobileSettings: {
        controls: false,
        showCloseIcon: true,
        download: false,
    }
});
lightGallery($("#web2")[0], {
    selector: 'this',
    mobileSettings: {
        controls: false,
        showCloseIcon: true,
        download: true,
    }
});
lightGallery($("#web3")[0], {
    selector: 'this',
    mobileSettings: {
        controls: false,
        showCloseIcon: true,
        download: true,
    }
});

How do I optimize the code so that I don't have to write a new number every time?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use a for loop:

let lowerLimit = 1;
let upperLimit = 3;

for (let i = lowerLimit; i <= uppperLimit; i++) {
    lightGallery($("#web" + i)[0], {
        selector: 'this',
        mobileSettings: {
            controls: false,
            showCloseIcon: true,
            download: false,
        }
    });
}
about 4 years ago · Juan Pablo Isaza Report

0

Consider the following.

$("[id^='web']").each(function(i, el){
  lightGallery($(el)[0], {
    selector: 'this',
    mobileSettings: {
      controls: false,
      showCloseIcon: true,
      download: false,
    }
  });
});

This will go over each one that has an ID that starts web and apply the same code.

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!