Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
How to select first child in jquery in Jquery functions of JQuery Examples
.first() used to select the first element from the children which have the same class name.In the following example, when you click the click here first 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").first().css("color", "red");

    <div class="exam">Click here to apply css red color to first 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