JSFiddle - React, Tailwind, and code Playground

by CME64

HTML

<div>
    <span>secondprev</span><br/>
    <span>firstprev</span>
    <div></div>
    
    <div id="errorDate">from here</div>
    <div></div>
    <div></div>
    <span>firstNext</span><br/>
    <span>secondNext</span>
    <div></div>
</div>

JavaScript

$(document).ready(function(){
    $('#errorDate').nextAll('span:first').css('background-color','red');
    $('#errorDate').prevAll('span:first').css('background-color','lime');
    // the folloing only work if the span is directly next to your selection
    $('#errorDate').next('span').css('background-color','yellow');
    $('#errorDate').prev('span').css('background-color','yellow');
});