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

116
Views
Take two elements in iteration jQuery

I want fill my website with my items from db, and it has to fit to my template - two animals in one line, if there is odd number of animals - the last one is one in the line.

How I should make fillResults function which take two animals from iteration and gives it to addAnimalsMen which fills my template?

function findAnimals(gender, catteryStatus, websiteVisibilityStatus) {
$.ajax({
    url: "/admin/api/animals?" + prepareUrl(gender, catteryStatus, websiteVisibilityStatus),
    type: "get",
    dataType: "json",
    contentType: "application/json"
})
.done(function (response) {
    fillResults(response, gender);
})
.fail(function(jqxhr, textStatus, errorThrown){
    displayErrorInformation(jqxhr.responseText);
});
}

function fillResults(response, gender) {
    $("#records_animals_man").empty();
    var animals = response;
    if(gender == 'M'){
        var counter = 0;
        animals.forEach(function(animal){
       counter++;
       if(counter%2 != 0){
            var firstAnimal = animal;
       } else if(counter%2 == 0){
            var secondAnimal = animal;
       }
       addAnimalsMen(firstAnimal, secondAnimal);

        });
    }

}

function addAnimalsMen(firstAnimal, secondAnimal) {
    $('#records_animals_man').append(
        '<div class="rounded bg-light shadow-sm my-5 p-3 text-center">' +
            '<div class="form-row text-center">' +
                '<div class="col-md-2"></div>' +
                prepareAnimalToShow(firstAnimal) +
                prepareAnimalToShow(secondAnimal) +
            '</div>' +
        '</div>'
    );
}


function prepareAnimalToShow(animal){
    return '<div class="col-md-4 col-sm-10 col-xs-12 p-4 ml-4 text-center text-secondary border justify-content-center">' +
                                 '<span><strong>' + animal.lineageName + '</strong></span><br><br>' +
                                  prepareImageToShow(animal.image.imageFileName) +
                                 '<br><br><span>' + animal.websiteDescription + '</span><br><br>'+
                     '</div>';
}
about 4 years ago · Juan Pablo Isaza
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!