mardi 24 mai 2016

create a loop with an if else? with arrays of variables?

I am not sure if I am asking this right, but basically i am trying to simplify my code so I don't have to write the same thing 5 times. I have included two samples below. You can see that the only thing that changes is the event.X and the ".ia-event-x".

// For title
if (event.title) {
    $(".ia-event-title").html(event.title);
     $(".ia-event-title").addClass('ia-populated');
}
else if (!event.title) {
    $(".ia-event-title").removeClass('ia-populated');
}

// For Description
if (event.description) {
    $(".ia-event-description").html(event.description);
     $(".ia-event-description").addClass('ia-populated');
}
else if (!event.description) {
    $(".ia-event-description").removeClass('ia-populated');
}

Aucun commentaire:

Enregistrer un commentaire