Home > Net >  Jquey add Number to nth-child automatically
Jquey add Number to nth-child automatically

Time:08-25

How I can automatically add number to nth-child?

I would like to simplify it

2nd element will have no.1 3rd element will have no.2

$("page:nth-child(2) .footer .page-no span").text("1");
$("page:nth-child(3) .footer .page-no span").text("2");
$("page:nth-child(4) .footer .page-no span").text("3");
$("page:nth-child(5) .footer .page-no span").text("4");
$("page:nth-child(6) .footer .page-no span").text("5");
...

Thank you.

CodePudding user response:

$("page .footer .page-no span").text(function(){
  return $(this).closest("page").index();
});
  • Related