ArturK.
ArturK.

Reputation: 35

JQuery to css write nth-child()

so I need to make a slider for school. I know that I can use something like

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

I know it need to be like

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

My question is how to write Child Index value into nth-child using Jquery?

Upvotes: 0

Views: 61

Answers (2)

Bill Criswell
Bill Criswell

Reputation: 32921

You can use .eq() to avoid ugly string concatenation.

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

Upvotes: 0

six fingered man
six fingered man

Reputation: 2500

You use string concatenation:

$(".sliders img:nth-child(" + index + ")").css.......

Upvotes: 2

Related Questions