JQuery to css write nth-child()

JQuery to css write nth-child()

本文关键字:nth-child write to css JQuery      更新时间:2023-09-26

所以我需要为学校制作一个滑块。我知道我可以使用类似的东西

.sliders img:nth-child(Index) {}

我知道它需要像

 $(".sliders img").css.........

我的问题是如何使用 Jquery 将子索引值写入第 n 个子项?

使用字符串连接:

$(".sliders img:nth-child(" + index + ")").css.......
您可以使用

.eq()来避免丑陋的字符串串联。

$(".sliders img").eq(index - 1).css();