Consider following code snippet:

        <p class="foo">Something_3</p>
        function ReturnValue(){
            var countElem = $('.foo').prev('p').length
What will be printed to the console?
The prev() method returns the previous sibling element of the selected element. The prev() method returns all the previous sibling elements of the selected element. The prevUntil() - returns all previous sibling elements between two given arguments. If both parameters are empty, this method will return all previous sibling elements (same as the prevAll() method).

$('.foo').prev('p').length;          // 1
$('.foo').prevAll('p').length;       // 2
$('.foo').prevUntil('div').length;  // 2 ,because no parameters were passed

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes