-
-
Save anonymous/bc4b34653299426d17ff to your computer and use it in GitHub Desktop.
Get All Siblings
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
//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