使第n个孩子在IE8和更低的工作 [英] Making nth-child work in IE8 and lower

查看:87
本文介绍了使第n个孩子在IE8和更低的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码:

  .c-1:first-child,.c-2 :first-child,.c-1:nth-​​child(4n + 1){margin-left:0; } 

这是工作很好,但我需要模仿这个浏览器不支持nth-例如IE8。



我试过这个jQuery代码添加一个类但没有发生任何事情,这个代码是否正确?

  //在IE8中支持第n个子项
$('c-1:first-child')addClass('remove');
$('。c-2:first-child')。addClass('remove');
$('。c-1:nth-​​child(4n + 1)')。addClass('remove');


解决方案

您可以使用jQuery的



例如:



<$ p(

$ p> $('。c-1')。eq(0).addClass('remove');


I'm making use of the following code:

.c-1:first-child, .c-2:first-child, .c-1:nth-child(4n+1) { margin-left: 0; }

which is working great but I need to mimic this for browsers that do not support nth-child, like IE8.

I have tried this jQuery code to add a class but nothing happens, is this code right?

// Support nth child in IE8
$('.c-1:first-child').addClass('remove');
$('.c-2:first-child').addClass('remove');
$('.c-1:nth-child(4n+1)').addClass('remove');

解决方案

You can use jQuery's .eq(<index>) for this.

For example:

$('.c-1').eq(0).addClass('remove');

这篇关于使第n个孩子在IE8和更低的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆