CSS Selector - Execute a loop from a particular loop item

1

Good morning. Let's say I have a table with 100 rows, plus I'd like my each (JQuery) to start from row 15. Which Css selector should I use? Or does JQuery have any resources?

Thanks to everyone

    
asked by anonymous 14.08.2017 / 15:00

2 answers

1

There is a CSS selector. Following your example of a table with 100 tr lines, 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 the rows in your table would have a gray background by default, but that the background would be blue from line 15. Just apply this example in your each JS.

    
14.08.2017 / 15:07
1

You can use the slice function of the% javascript Array itself.

The function works as follows:

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

So, in your case it would look like this:

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

I hope I have helped!

    
14.08.2017 / 15:08