JSFiddle - React, Tailwind, and code Playground
by Oleh Aloshkin
HTML
<div id="parent" >
<a href="https://github.com/rnicholus" > GitHub </a>
<p>
123
</p>
<span> Span text </span>
<p> Paragraph text </p>
<div> Div text </div>
Text node
</div>
JavaScript
var allSiblings = document.querySelectorAll('#parent SPAN ~ *');
allSiblings = [].slice.call(allSiblings);
var referenceElement = document.querySelector('#parent > SPAN'),
currentElement = referenceElement;
do {
currentElement = currentElement.previousElementSibling;
currentElement && allSiblings.push(currentElement);
} while (currentElement);