Método jQuery slice()
❮ Métodos transversales de jQuery
Ejemplo
Inicie la selección de elementos <p> desde el elemento <p> con número de índice 2:
$("p").slice(2)
Definición y uso
El método slice() selecciona un subconjunto de elementos en función de su índice.
Un subconjunto es un conjunto que forma parte de un conjunto mayor.
Este método se usa para limitar la selección de elementos en un grupo, por un punto de inicio y final: el parámetro de inicio es un índice de inicio (comienza en 0) a partir del cual crear el subconjunto, y el parámetro de parada es un punto final opcional.
Sintaxis
$(selector).slice(start,stop)
Parameter | Description |
---|---|
start | Required. Specifies where to start the selection of elements. The index numbers start at 0. Note: Using a negative number will select elements from the end of the selected elements, instead of the beginning. |
stop | Optional. Specifies where to end the selection of elements. If omitted, the selection continues until the end of the set. The index numbers start at 0. Note: Using a negative number will select elements from the end of the selected elements, instead of the beginning. |
Pruébelo usted mismo - Ejemplos
Cómo usar ambos parámetros para seleccionar elementos <p> desde un punto de inicio y un punto final.
Usar un número negativo para comenzar la selección de elementos <p> contando desde el final, en lugar del principio.
Usando start y stop con un número negativo para iniciar la selección de elementos <p> contando desde el final.
❮ Métodos transversales de jQuery