JQuery: nth-child does not work in IE

I am using this code

$('.list-item:nth-child(5n)').after('<div class="clear"><img src="http://domain.com/image.jpg" width="780" height="80" alt="banner" /></div>') 

This works fine in Firefox and Chrome, but doesn't work in IE8, IE9 ...

+4
source share
5 answers

jQuery handles nth-child in the absence of native browser support. It works fine in IE7, 8, and 9+.

Fiddle: http://jsfiddle.net/jonathansampson/Y3MP4/

+4
source

nth-child not supported in IE 6-8. IE9 supports it. See here .

See this question for a possible workaround.

+2
source

Something else seems to be wrong. Your code should work even in IE6, although IE <9 does not support nth-child, the jQuery (Sizzle) selector mechanism implicitly processes it for you.

Release this code:

 <script> $("ul").remove(); var ul = $("<ul>"); for (var i = 1; i < 100; i++) { $("<li>", { "class" : "list-item", html : i }).appendTo(ul); } ul.appendTo(document.body); $('.list-item:nth-child(5n)') .after('<div class="clear">Clear!</div>') </script> 

You see "Clear!" comments? Even in IE6 you have to ...

+1
source

Actually there is a script that you can load into your js folder and add some conventions to your header, and nth-child will work in IE 6, 7 and 8. you can find out more here and if you need to use rounded corners , you will need to install this other script called curvycorners.js They really save time. Good luck

0
source

The nth-child jQuery selector does not work in some cases involving complex selectors in IE8.

The following needs to be changed in IE8.

 //Works fine in IE9+, FF and Chrome. //dataColumn = jQuery('.table-header div.rf-edt-hdr + div table table tbody > tr:nth-child(1) td:nth-child(1)'); //headerColumn = jQuery('div.table-header > div.rf-edt-hdr table table > tbody > tr td:nth-child(1)'); dataColumn = jQuery('.table-header div.rf-edt-hdr + div table table tbody > tr').eq(0).find('td').eq(0); headerColumn = jQuery('div.table-header > div.rf-edt-hdr table table > tbody > tr td').eq(0); 

NOTE. nth-child is based on 1 index. eq () is based on 0-indices.

0
source

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


All Articles