function siblings(elem) {
return Array.from(elem.parentNode.children).filter(el => el !== elem);
}
document.querySelector()
, но нет селектора для всех соседних элементов.function siblings(elem) {
let siblings = [];
let sibling = elem;
while (sibling.previousSibling) {
sibling = sibling.previousSibling;
sibling.nodeType == 1 && siblings.push(sibling);
}
sibling = elem;
while (sibling.nextSibling) {
sibling = sibling.nextSibling;
sibling.nodeType == 1 && siblings.push(sibling);
}
return siblings;
}