What is the Jquery Event ? (Part 4)


Event are visitor action created on web application. If you have worked with asp.net web-form then you might be familiar with event, But web-form event perform the full post-back of page. where as Jquery event will not perform the post-back of page. This is the main advantage of using Jquery event in web application.

Some example of event are

1. Mouse hover
2. Button click
3. Radio button Selection
4. Checkbox selection
5. double click
6. MouseEnter
7. MouseLeave
8. Keyup
9. Keydown
10. Keydown
11. Submit
12. Change
13. Focus
14. Blur
15. Load
16. Resize
17. Scroll
18. Unload

Click Event Example:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
     <script src="../Scripts/jquery.min.js"></script>
    <script>
        $(function () {
            $("button").click(function () {
                $("#Line1").hide();
            });
        });
    </script>
</head>
<body>
    <p id="Line1">This is the first line</p>
    <p>This is the Second line</p>
    <button>Click Here</button>
</body>
</html>

hover event example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
     <script src="../Scripts/jquery.min.js"></script>
    <script>
        $(function () {
            $("button").hover(function () {
                $("#Line1").hide();
            });
        });
    </script>
</head>
<body>
    <p id="Line1">This is the first line</p>
    <p>This is the Second line</p>
    <button>Click Here</button>
</body>
</html>

double click event example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
     <script src="../Scripts/jquery.min.js"></script>
    <script>
        $(function () {
            $("button").dblclick(function () {
                $("#Line1").hide();
            });
        });
    </script>
</head>
<body>
    <p id="Line1">This is the first line</p>
    <p>This is the Second line</p>
    <button>Click Here</button>
</body>
</html>

MouseEnter Example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
     <script src="../Scripts/jquery.min.js"></script>
    <script>
        $(function () {
            $("button").mouseenter(function () {
                $("#Line1").hide();
            });
        });
    </script>
</head>
<body>
    <p id="Line1">This is the first line</p>
    <p>This is the Second line</p>
    <button>Click Here</button>
</body>
</html>

Focus Event Example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
     <script src="../Scripts/jquery.min.js"></script>
    <script>
        $(function () {
            $("input").focus(function () {
                $(this).css("background-color", "green");
            });
        });
    </script>
</head>
<body>
    <div>
         FirstName: <input type="text" name="txtUserFirstName" value=" " /> <br />
          LastName : <input type="text" name="txtUserLastName" value=" " /> <br />
          EmailId : <input type="text" name="txtEmailId" value=" " /> <br />
        <button>Submit</button>
    </div>
</body>
</html>

Summary:

We have learnt some of the basic concept of event in Jquery Library

Advertisement

One thought on “What is the Jquery Event ? (Part 4)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.