I would like to change the color of some badges in an list.
<div id="tree">
<ul class="list-group">
<li class="list-group-item node-tree" ><span class="icon expand-icon glyphicon glyphicon-minus"></span><span class="icon node-icon"></span><a href="#" style="color:inherit;">Test</a><span class="badge">123</span><span class="badge">123</span><span class="badge">3223</span><span class="badge">23</span><span class="badge">323</span></li>
<li class="list-group-item node-tree"><span class="icon expand-icon glyphicon glyphicon-minus"></span><span class="icon node-icon"></span><a href="#" style="color:inherit;">Test 1</a><span class="badge">321</span><span class="badge">123</span><span class="badge">3223</span><span class="badge">23</span><span class="badge">323</span></li>
</ul>
</div>
It still works with jQuery, for example with:
$("#tree .list-group-item").each(function(){
$(this).find('.badge:eq(4)').css('background-color','#bf5329');
$(this).find('.badge:eq(4)').css('color','#fff');
$(this).find('.badge:eq(3)').css('background-color','#2ab27b');
$(this).find('.badge:eq(3)').css('color','#fff');
$(this).find('.badge:eq(2)').css('background-color','#bf5329');
$(this).find('.badge:eq(2)').css('color','#fff');
$(this).find('.badge:eq(1)').css('background-color','#2ab27b');
$(this).find('.badge:eq(1)').css('color','#fff');
$(this).find('.badge:eq(0)').css('background-color','#3B4752');
$(this).find('.badge:eq(0)').css('color','#fff');
});
But my Problem is, when ill change the tree, i need to call the method again (and again..) - so i would prefer to create the same with CSS only, but when ill try with:
#tree .list-group-item .badge:nth-child(1) {
background-color: #bf5329;
}
Its not setting EVERY .list-group-item, only the first one (and there are about 100 "rows".
Any ideas?
Here is a fiddle: https://jsfiddle.net/DTcHh/30190/
Update with CSS: https://jsfiddle.net/DTcHh/30192/
Thanks for your answers - but ill still have a problem if there are some more
<span>
inside my
.list-group-item
In this case its a treeview, and there are some "indent" classes. Check out here:
https://jsfiddle.net/DTcHh/30196/
Any more ideas?