Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to select last child in jquery in Jquery functions of JQuery Examples
1588 Views
Hints 
.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
<html>

<head>
    <title>HTML-JQuery</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

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

<body>
    <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>
    </div>
</body>

</html>
Demo 
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details