jQuery Tutorial Tutorials - jQuery .prevAll() method

jQuery .prevAll() method

The .prevAll() method in jQuery is used to get all preceding siblings element of the matched elements.

jQuery .prevAll() method Syntax

.prevAll()
.prevAll(selector)

jQuery .prevAll() method Example

example

Find all the items before Item3 and highlight them

HTML

<ul>
    <li class="one">item1</li>
    <li>item2</li>
    <li class="third">item3</li>
    <li>item4</li>
    <li>item5</li>
</ul>

jQuery

$(".third").prevAll();
$(".third").prevAll('li');
$(".third").prevAll('.one');

Result

[<li>item2</li>,<li class="one">item1</li>]
[<li>item2</li>,<li class="one">item1</li>]
[<li>item1</li>]

Try now

Date:2019-08-26 14:12:31 From:www.Lautturi.com author:Lautturi