Alternative for nth-child for older IE browsers

Is there an alternative for targeting elements using nth-child() for older IE browsers?

There will also be enough Javascript (not jquery).

EDIT: if additional libraries cannot be added to the page.

+4
source share
4 answers

You can use jQuery : nth-child () selector ;

 $("li:nth-child(even)") // target even li's $("li:nth-child(odd)") // target odd li's $("li:nth-child(5n)") // target the fifth li 
+6
source

it sucks a little, but you can

 ul > li {} /* first-child, overwritten by below */ ul > li + li {} /* second-child, overwritten by below, etc */ ul > li + li + li {} ul > li + li + li + li {} 

Repeat as necessary.

+16
source

There is Selectivizr: http://selectivizr.com/

:nth-child supported in every javascript framework that works with it, including jQuery.

The big advantage when using this is that it reads directly from your CSS files, rather than writing extra javascript (this is unobtrusive). You can simply use the advanced selectors as usual.

+4
source
+1
source

Source: https://habr.com/ru/post/1389349/


All Articles