Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nth-of-type alternative for IE8 [duplicate]

I have rows of product divs. Need to add a clear div after every fourth item. 4 to a row.

I'm using jQuery('.product:nth-of-type(4n+2)').after("<div class='clear'></div>"); right now, but that doesn't support IE8. And since we're using jQuery, selectivizrs fix won't work in this case.

I've also tried

            addDynamicRow = function() {
            var divs = $(".product-section > .product");
            for(var i = 0; i < divs.length; i+=4) {
              divs.slice(i, i+4).wrapAll("<div class='row'></div>");
            }  

            $('.row').after("<div class='clear'></div>")   
        }

        addDynamicRow();

But that grabs all of the product divs in the other product-section wrappers as well and puts them into groups of four regardless of where they're at.

Anyone know a work-a-round? I havn't been able to find a solution.

Thanks!

1/15/13 Update: jQuery 1.9 now supports the following CSS3 selectors across all browsers, all the way back to IE6: :nth-last-child, :nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :target, :root, and :lang.

like image 930
Christopher Marshall Avatar asked Jul 17 '12 21:07

Christopher Marshall


2 Answers

Ended up using https://github.com/keithclark/JQuery-Extended-Selectors in an IE conditional statement. It's working now.

like image 131
Christopher Marshall Avatar answered Oct 22 '22 16:10

Christopher Marshall


JQuery-Extended-Selectors

It will solve your problem, it helps all css3 selector classes.

like image 43
Santosh A. Avatar answered Oct 22 '22 18:10

Santosh A.