This is the closest I got, but it adds an active class to all status-card .
This is because after adding each status-card you add other classes to all the status cards added so far:
$.each(a.agents, function(b, c) { ....
So, active classes are added to all other cards, because it could be callStatus in the last outer loop.
You can calculate className based callStatus before creating HTML, and then use this className in HTML, like this:
function getClassNameByStatus (callStatus) { switch(callStatus){ case "On Call": return "active"; case "Idle": return "idle"; default: return "away"; } } $.each(a.agents, function(b, c) { var className = getClassNameByStatus(c.callStatus); var content = '<div class="status-card' + className + '">' + ....;
source share