lundi 30 mars 2015

Find a terminal DOM tree element that is rendered next to the right (or left) to a given one

I have a semi-arbitrary DOM tree with an INPUT control somewhere in it. For example:



.terminal { white-space: no-wrap; display: inline-block; }

<div>
<span class="terminal">Alpha</span>
<span><span class="terminal">Beta</span></span>
<span class="terminal"><input value="Gamma"></span>
<span><span><span class="terminal">Delta</span></span></span>
</div>


I need to find the next (as rendered) terminal element to the left and to the right of the INPUT. Is there an easy way to do this with jQuery?


Bonus points for a solution that also is able to find a terminal element directly above and below of the INPUT in case when there are so many entries that they span across several lines.


Aucun commentaire:

Enregistrer un commentaire