Consider following code snippet:

<div>
    <p class="foo">Something_1</p>
    <p>Something_2</p>
    <p>Something_3</p>
</div>
<script>
        function ReturnValue(){
        var countElem = $('.foo').next('p').length
                    +$('.foo').nextAll('p').length
                    +$('.foo').nextUntil('p').length;
        console.log(countElem);
    }; 
</script>
What will be the value of countElem variable after executing the code?
Explanation
The next() method returns the next sibling element of the selected element. The nextAll() method returns all next sibling elements of the selected element. The nextUntil() method returns all next sibling elements between the selector and stop.

console.log($('.foo').next('p').length); // 1
console.log($('.foo').nextAll('p').length); // 2
console.log($('.foo').nextUntil('p').length); // 0

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback