Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

add a class to an li element while looping

Hi
i have an ajax call and i loop it and present it. all this works. the issue: i create the li element, and i need to add a class only to the odd ones.

how to do it?

here is the code i have:
                for(var ii=0;ii<data.length;ii++) {
                    //alert(data[ii].date);

                    var li = '<li>
                          <div class="timeline-badge">
                          <i class="fa fa-exclamation-circle"></i>
                          </div>
                          <div class="timeline-panel">
                            <div class="timeline-heading">
                              <h4 class="timeline-title">'+data[ii].thetype+'</h4>
                              <p>
                              <small class="text-muted">
                              <i class="glyphicon glyphicon-time"></i>'+data[ii].date+'
                              </small>
                              </p>
                            </div>
                            <div class="timeline-body">
                              <p>'+data[ii].message+'</p>
                            </div>
                          </div>
                        </li>';

                        $("#alertitin").prepend( li );
                }

Open in new window



best regards
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derrida
derrida

ASKER

perfect thanks