jQuery Tutorial Tutorials - jQuery .next() method

jQuery .next() method

The .next() method in jQuery is used to get the following sibling element.

jQuery .next() method Syntax

.next()
.next(selector)

jQuery .next() method Example

example

Find the very next sibling of Item 3. optionaly filtered by a selector.

HTML

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

jQuery

$(".third").next();
$(".third").next('li');
$(".third").next('.five');

Result

[<li>item4</li>]
[<li>item4</li>]
[]

Try now

Date:2019-08-26 13:55:48 From:www.Lautturi.com author:Lautturi