Via selector I’m almost certain it’s impossible, however there is the method .slice()
that is proper to "filter" taking only what you want, example:
$(function () {
var els = $('.img').slice(9);
//Exibe os elementos
els.each(function () {
console.log(this);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
<div class='img'><img src='imagem.jpg'></div>
Note that I used 9
instead of 10
, this because the Indice starts from scratch, ie the first element belongs to the index 0
, as well as second belongs to the index 1
(as in an array).
Note also that slice
allows you to set the last to be picked up also if you set the second parameter .slice(primeiro, ultimo)
, for example:
$(function () {
//Pega do terceiro até o quinto elemento
var els = $('.img').slice(2, 5);
//Exibe os elementos
els.each(function () {
console.log(this);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class='img'>1</div>
<div class='img'>2</div>
<div class='img'>3</div>
<div class='img'>4</div>
<div class='img'>5</div>
<div class='img'>6</div>
<div class='img'>7</div>
<div class='img'>8</div>
<div class='img'>9</div>
<div class='img'>10</div>
Picking up the last elements with jQuery.Lice
Just apply the negative value:
$(function () {
//Pega o 10 e 9 elementos
var els = $('.img').slice(-2);
//Exibe os elementos
els.each(function () {
console.log(this);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class='img'>1</div>
<div class='img'>2</div>
<div class='img'>3</div>
<div class='img'>4</div>
<div class='img'>5</div>
<div class='img'>6</div>
<div class='img'>7</div>
<div class='img'>8</div>
<div class='img'>9</div>
<div class='img'>10</div>
To limit pass the second parameter, in the example -2 removes the last 2 elements:
$(function () {
//Pega do quinto até o oitavo elemento
var els = $('.img').slice(-6, -2);
//Exibe os elementos
els.each(function () {
console.log(this);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class='img'>1</div>
<div class='img'>2</div>
<div class='img'>3</div>
<div class='img'>4</div>
<div class='img'>5</div>
<div class='img'>6</div>
<div class='img'>7</div>
<div class='img'>8</div>
<div class='img'>9</div>
<div class='img'>10</div>
Dude Do you already have code? HTML/CSS/JS ? Only with your report do not answer you precisely....
– hugocsl
ok I know only I’ve read a lot of jquery manual selector and I haven’t found anything like it so I don’t have Cod. if anyone knows at least the name of the function I’ll come later.
– Jasar Orion