jQuery .prevAll() first of bunch
HTML
<div><span>Hello</span>
<p class="selected">navHello Again</p>
</div>
<p class="selected">Hello Again</p>
<p class="selected">Hello Again</p>
<p>And Again</p>
<p>And Again</p>
<p class="last">And Again</p>
JavaScript
$("p.last").prevAll(".selected").first().css("background", "yellow");
// The reason why the 2nd "Hellow Again" is selected is because the jQuery array of elements if built storing elements from bottom to the top, so the bottom is the first, and as it trasverses up, it gets appended additionally.