Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the previous visible element jquery

I have a <ul> like

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li style="display:none;">4</li>
<li class="curSelected">5</li>
<li>6</li>
</ul>

Now from <li> 5 I want the reference of the previous visible element i.e <li> 3

How can I get it?

I tried $('li.curSelected').prev(":visible:last");

But this is not working.

Please help.

like image 296
Seeker Avatar asked Jun 12 '13 07:06

Seeker


1 Answers

Try this:

$('li.curSelected').prevAll(":visible:first");

prev() returns only the immediate element preceding the selected one. prevAll() returns all previous.

like image 104
Konstantin Dinev Avatar answered Oct 03 '22 21:10

Konstantin Dinev