How to find all Siblings of the currently selected DOM object

前端 未结 11 1337
轻奢々
轻奢々 2020-12-08 04:25

What is the perfect way to find all nextSiblings and previousSiblings in JavaScript. I tried few ways but not getting accurate solution. If any element is selected, I need t

11条回答
  •  被撕碎了的回忆
    2020-12-08 05:19

    back to 2017:
    Maybe there is a better answer but that good and a little bit cleaner

    function sibiling(dom, query) {
       var doms = dom.parentElement.querySelectorAll(query);
       return [].slice.call(doms).filter( d => d != dom);
    }
    

提交回复
热议问题