I have a problem displaying “zebra” list after filtering results.
I have a zebra list which display perfect here is the code:
$('ul li:odd').addClass('zebra_odd');
$('ul li:even').addClass('zebra_even');
The problem comes when I filter that list an input like this:
$('input').keyup(function() {
var textboxVal = $(this).val().toLowerCase();
$('ul li').each(function() {
var listVal = $(this).text().toLowerCase();
if(listVal.indexOf(textboxVal) >= 0) {
$(this).show();
} else {
$(this).hide();
}
i.e. on the list I have this values: a1, b1, a2, b2, a3, b3. The list display the values on zebra rows perfect, but if I filter the data i.e. “a” it will show me a1, a2, a3 all in white background, it kept the old odd, even values. Thanks
You can write a function to Update
odd,evenclasses after filtering the elements like thisWorking Fiddle
Dont forget the
:visibleselector, or it will take hidden elements into account and hence wont work properly.