Consider following code snippet:

    $("div p").css('color','red');
    $("div p:last-child").css('color','green');
    $("div p:last").css('color','blue');
What will be the colors of p elements after execution the code?
The :last selector selects only the last element - The :last-child selector selects all elements that are the last child of their parent.

$("div p").css('color','red'); // will make all p elements to be red;
$("div p:last-child").css('color','green'); // will make two last element to be green;
$("div p:last").css('color','blue'); // selects only the last element and make it to be red;

Follow CodeGalaxy

Mobile Beta

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