Created
February 23, 2013 23:20
-
-
Save dlabey/5021803 to your computer and use it in GitHub Desktop.
Get all direct siblings between 2 elements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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