How to get not a neighboring element, but through it in JS?

  • 0
    How to get in pure JavaScript not the previous or adjacent element, but for example in css there is a tilde icon ~ which allows you to walk through the elements inside the parent, even if there is a p if such an analogue is in pure JavaScript? allowing you to walk inside the parent? by property type previousElementSibling nextElementSibling , but accessed through the element
    JavaScript Anonymous, Jul 28, 2019

  • 3 Answers
  • 0
    <ul class="menu">
    <li class="first">1</li>
    <li class="last">5</li>

    const menu = document.querySelector('.menu')
    Joseph Lin

  • 0
    There are no such methods. Take next, then another next, etc.

  • 0 / Pare ... if all elements inside the parent are needed. You can filter them and get what you need.

    Or call

    element.nextElementSibling.nextElementSibling // Соседний через один

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!