Syden Syden - 1 year ago 79
jQuery Question

jQuery numeric array comparison


<section class="DataContent"></section>

Content is appended dynamically on .DataContent through jQuery arrays loop

see JSFiddle

How could I make li.rate appear on red if span.ratePercent is < 0, on green if span.ratePercent > 0 and on grey if span.ratePercent == 0?

Trying some functions like:
in the fiddle but it always end up affecting all li.rate color equally.

Thank you for your time!

Answer Source

You can use benefit of your loop for appending li elements. Just change your li element to:

<li class="rate'+[i]+'">

And in calculateRate() function change the .rate class for every if statement:


Complete working code : jsFiddle

Now you can have as many as you want list objects, and it will loop throught each, and according from their ratePercent value it will set properly color of text.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download