CSS Selector - Run a loop from a particular loop item

Asked

Viewed 28 times

1

Good morning. Let’s say I have a table with 100 rows, the more I’d like my each (Jquery) to start from line 15. Which Css selector should I use? Or Jquery has some resource for this?

Thanks to all

2 answers

1


There is a CSS selector. Following your example of a table with 100 rows tr, you could use something like this:

tr {
    background: gray;
}
tr:nth-child(n + 15) {
    background: blue;
}

In this case you would be saying that all rows in your table would by default have a gray background, but that the background would be blue from line 15. Just apply this example to your each JS.

1

You can use the function slice javascript itself Array.

The function works as follows:

I have an array [12, 32, 31, 23, 43] and I want to take only from the third, ie I want to take only the positions [31, 23, 43], then in this case would do so: [12, 32, 31, 23, 43].slice(2), that is, I would cut off the first two array positions.

So in your case I’d be like this:

$('.seu-seletor').slice(15).each(function() { /* PERCORRENDO O ARRAY */ });

I hope I’ve helped!

  • I do not intend to cut out the items, just remove them from the selection. More worth, helped also!

  • 1

    Oops, I’m glad I helped in some way! Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.