Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
For each in jquery example in Jquery functions of JQuery Examples
1189 Views
Hints 
each() function used to run function on elements, which are have same class name.In following example, i wrote each function to check which element have text of 5 and apply color red.
Example
<html>

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

    <script type="text/javascript">
        $(document).ready(function () {
            $("div.element").each(function () {
                if ($(this).text() === "5") {
                    $(this).css("color", "red");
                }
            });
        });
    </script>
</head>

<body>
    <div class="element">1</div>
    <div class="element">2</div>
    <div class="element">3</div>
    <div class="element">4</div>
    <div class="element">5</div>
    <div class="element">6</div>
</body>

</html>
Demo 
Next Topics
Next lessons of current book.
  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