JSFiddle - React, Tailwind, and code Playground
HTML
<span>before</span>
<div style="background-color:red;height:10px;width:10px;margin-left:15px;" id="2"> </div>
<span>after</span>
JavaScript
$(function(){
var prevIt = $('#2').prev();
var nextIt = $('#2').next();
alert(prevIt.text() + ";" + nextIt.text());
});