tags:

views:

40

answers:

3

What is the best way to give support nth-child in one shot to all IE version?

I want to give style like this. for some particular pages.

#products tr:nth-child(even) {
  background-color: red;
}


#products tr:nth-child(odd) {
  background-color: white;
}
+1  A: 

That project gives you "native" support for these and many others CSS3 selectors for at least IE7/8.

But here you'll have a problem with IE7 which doesn't support background-color for tr.

Crozin
i need only support for nth child. don't need other selectors
metal-gear-solid
@Crozin - Would it be wise to use whole library just for one selector?
metal-gear-solid
IMHO yes. That's a huge facilitation for now, and for future. Oh.. and the best is that you don't have to change any code. Just attach that JS code and "magically" your code works! ;)
Crozin
@metal: You'll almost certainly find that you need to support another missing feature in IE, so better to already have a library that fixes everything before it becomes a problem.
DisgruntledGoat
+1  A: 

You can do it in javascript.

var table = document.getElementById('products');

var rows = table.getElementByTagsName('tr');

for (var i = 0; i < rows.length; ++i)
{
   if ( (i % 2) == 0 )
   {
       rows[i].className = 'even';
   }
}

then do your CSS like this:

#products tr td
{
    background-color: white;
}

#products tr.even td
{
    background-color: red;
}

If you have used a javascript library, you could have done this :

$('#products tr:even').addClass('even');
Boris Guéry
A: 

You can do this in jQuery too, and they'll likely have solved your cross browser issue.

$('#products').children('tr:even').css('background-color', 'red');
$('#products').children('tr:odd').css('background-color', 'white');
Tejs