Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
If in jquery example in Jquery functions of JQuery Examples
3268 Views
Hints 
Simple IF statement is used to execute particular statements with certain conditions. It controls the flow of statement execution. If given condition is true then the block of statements will get executed.
Syntax
if (condition or expression)
{
    statements;
}
Example Hints 
In the following example, If the entered number is less than or equal to 5 then the if condition block executed else the else block executed.
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.num").click(function () {
                var a = $("input").val();
                if (a <= 5) {
                    alert("Entered value is less than 6");
                } else {
                    alert("Entered value is more than 6");
                }
            });
        });
    </script>
</head>

<body>
    <div>Enter number here</div>
    <input type="text" />
    <div class="num">Click here to run the code</div>
</body>

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