| 2 | |
| 3 | // https://gomakethings.com/finding-the-next-and-previous-sibling-elements-that-match-a-selector-with-vanilla-js/ |
| 4 | function getNextSibling(elem, selector) { |
| 5 | // Get the next sibling element |
| 6 | let sibling = elem.nextElementSibling |
| 7 | |
| 8 | // If there's no selector, return the first sibling |
| 9 | if (!selector) { |
| 10 | return sibling |
| 11 | } |
| 12 | |
| 13 | // If the sibling matches our selector, use it |
| 14 | // If not, jump to the next sibling and continue the loop |
| 15 | while (sibling) { |
| 16 | if (sibling.matches(selector)) { |
| 17 | return sibling |
| 18 | } |
| 19 | sibling = sibling.nextElementSibling |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | /* Panel Stuff */ |
| 24 | |