Nth-of-type alternative for IE8

I have a line div. You must add a clear div after every fourth element. 4 to the line.

I am using jQuery('.product:nth-of-type(4n+2)').after("<div class='clear'></div>"); right now, but it does not support IE8. And since we are using jQuery, selectivizrs fix will not work in this case.

I 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 it captures all commodity divs in other packages of the product section and puts them in groups of four no matter where they are.

Does anyone know a job? I could not find a solution.

Thanks!

Update 1/15/13: jQuery 1.9 now supports the following CSS3 selectors in all browsers, up 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.

+6
source share
5 answers

Finished using https://github.com/keithclark/JQuery-Extended-Selectors in IE conditional. He is working now.

+5
source

Jquery-extended-selectors

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

+2
source

The .filter method can be used to fix missing CSS3 jQuery support:

 jQuery('.product').filter(function(i){return i%4==2;}) 

although it emulates nth-child , not nth-of-type , and only in the current set of selected elements instead of being based on their DOM position.

+1
source

If you are happy to use the javascript solution, then the best of them is Selectivz . It adds IE support for a range of advanced CSS selectors.

It does this using any of several libraries, including jQuery. However, on the home page, it is worth noting that nth-of-type is referred to as not supported when used in conjunction with jQuery. However, it works with MooTools, Prototype, and other libraries. I don't know why he has a problem with jQuery.

If this does not work for you, an older script called IE9.js may help you. This is a big hack that tries to add a whole bunch of missing functionality to older versions of IE, including nth-of-type and other CSS selectors. He is also trying to fix a bunch of IE errors.

Any of these libraries can work for you and allows you to use advanced CSS selectors without worrying about older versions of IE. Let them go.

+1
source

If you do not want to download the full library of selectors, check this out: https://gist.github.com/oliverbenns/6740630

0
source

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


All Articles