How can I get the elements between 2 other elements?
Like if I had:
You might want to first check if elements come in the proper order, othenwise nextUntil will return unexpected set of elements.
/**
* Returns an array of sibling elements between `from` and `to` including `from` and `to`
*/
function getElementsInBetween (from, to) {
var range = [];
if (from.index() > to.index()) { //ensure that 'from' is before 'to'
from = [to, to = from][0]; //swapping from and to
}
if (from.is(to)) {
range = [from];
} else {
range = from.nextUntil(to).add(from).add(to);
range = $.makeArray(range);
}
return range;
};