Consider following code snippet:

<div>
    <p>Something_1</p>
    <p>Something_2</p>
    <p>Something_3</p>
</div>
<script>
    $("p").eq(3).css('color','yellow');
    $("p").eq(2).css('color','blue');
    $("p").eq(1).css('color','green');
    $("p").eq(0).css('color','red');
    $("p").eq(-1).css('color','green');
    $("p").eq(-2).css('color','blue');
    $("p").eq(-3).css('color','yellow');
</script>
What will be the color of <p> elements?
Explanation
Given a jQuery object that represents a set of DOM elements, the .eq() method constructs a new jQuery object from one element within that set. The supplied index identifies the position of this element in the set. In the code example : $("p").eq(-3) = $("p").eq(0)

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
JavaScript quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes