Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
How to select last child in jquery in Jquery functions of JQuery Examples
.last() used to select the last element from the children which have the same class name.In the following example, when you click the "click here" last child will change into red color.
Example code

    <script type="text/javascript" src=""></script>

    <script type="text/javascript">
        $(function () {
            $("div.exam").click(function () {
                $("div.exam div.num").last().css("color", "red");

    <div class="exam">Click here to apply css red color to last element
        <div class="num">first</div>
        <div class="num">second</div>
        <div class="num">third</div>
        <div class="num">fourth</div>
        <div class="num">last</div>

Previous Topics
Previous lessons of current book.
Best Lessons of "JQuery Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details