Skip to content

Instantly share code, notes, and snippets.

@dlabey
Created February 23, 2013 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlabey/5021803 to your computer and use it in GitHub Desktop.
Save dlabey/5021803 to your computer and use it in GitHub Desktop.
Get all direct siblings between 2 elements.
/**
* Between Elements
* Gets all direct siblings between 2 elements.
*
* @param {Object} The first element or the current element (from itself, starting).
* @param {Object} The last element (ending).
* @param {Array} An array for the elements to be pushed in to.
* @returns _betweenElements|Array
*/
function _betweenElements(currentElement, lastElement, elements) {
try {
if (!currentElement.nextSibling || currentElement.nextSibling === lastElement) {
return elements;
} else {
elements.push(currentElement.nextSibling);
return _betweenElements(currentElement.nextSibling, lastElement, elements);
}
} catch (exception) {
console.log(exception);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment