Skip to content

Instantly share code, notes, and snippets.

Created November 30, 2012 02:29
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 anonymous/bc4b34653299426d17ff to your computer and use it in GitHub Desktop.
Save anonymous/bc4b34653299426d17ff to your computer and use it in GitHub Desktop.
Get All Siblings
//there has SPAN01 ~ 05
function getAllSiblings(ele, includeMe) {
var n = ele.parentElement.firstElementChild;
var aryEles = [];
while (n) {
if (n === ele) includeMe ? aryEles.push(n) : '';
else aryEles.push(n);
n = n.nextElementSibling;
}
return aryEles;
}
var s3 = document.getElementById('span03');
console.log(getAllSiblings(s3, true)); //[span01, span02, span03, span04, span05]
console.log(getAllSiblings(s3, false)); //[span01, span02, span04, span05]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment