The Wayback Machine - https://web.archive.org/web/20240808231925/https://www.geeksforgeeks.org/jquery-events/
Open In App

jQuery Events

Last Updated : 16 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

jQuery events are actions or occurrences that happen on a web page, such as clicks, hover, or keypress. jQuery provides methods to handle and respond to these events with ease.  jQuery events are used to create dynamic web pages.

Syntax:

$(selector).method(function)

Here We will explore some basic events along with their basic implementation of examples.

jQuery click() Event

jQuery click is a mouse event that triggers when an element is clicked by the mouse pointer.

Syntax:

$(selector).click(function);

Example: In this example, we are using the click() event.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
  
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function () {
            $("p").click();
        });
    </script>
  
    <style>
        p {
            display: block;
            width: 300px;
            padding: 20px;
            font-size: 30px;
            border: 2px solid green;
        }
    </style>
</head>
  
<body>
    <center>
        <!-- click on this method -->
        <p onclick="alert('paragraph was clicked')">
            Geeksforgeeks.
        </p>
    </center>
  
</body>
  
</html>


Output

event-click

jQuery dblclick() Event

jQuery dblclick is a mouse event that triggers when an element is double-clicked by the mouse pointer.

Syntax:

$(selector).dblclick(args);

Example: In this example, we are using dblclick() event.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
  
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function () {
            $("p").dblclick();
        });
    </script>
  
    <style>
        p {
            display: block;
            width: 300px;
            padding: 20px;
            font-size: 30px;
            border: 2px solid green;
        }
    </style>
</head>
  
<body>
    <center>
        <!-- click on this method -->
        <p onclick="alert('dblclick event has trigged')">
            Geeksforgeeks.
        </p>
    </center>
  
</body>
  
</html>


Output

event-dblclick-1

jQuery mouseenter() and mouseleave() Events

jQuery mouseenter is a mouse event that triggers when the mouse pointer enters an element, and mouseleave is a mouse event that triggers when the mouse pointer leaves an element.

Syntax:

$(selector).mouseenter(function)  
and
$(selector).mouseleave(function)

Example: In this example, we have a div with a class “box.” It changes color to white on mouseenter and black on mouseleave using jQuery.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
  
    </script>
    <style>
        .box {
            width: 200px;
            height: 100px;
            background-color: lightblue;
        }
  
        .box:hover {
            background-color: gray;
        }
    </style>
</head>
  
<body>
    <h2>
        Mouse Enter and Mouse Leave Events Example
    </h2>
  
    <div class="box">
        Hover over the div
    </div>
  
    <script>
        $(document).ready(function () {
            // Using the mouseenter event 
            $(".box").mouseenter(function () {
                $(this).css("color", "white");
            });
  
            // Using the mouseleave event
            $(".box").mouseleave(function () {
                $(this).css("color", "black");
            });
        });
    </script>
</body>
  
</html>


Output

event-mouseenter-mouseleave

The Complete List of jQuery events are listed below:

jQuery Mouse events

jQuery Mouse events handle interactions with the mouse, like click, hover, dblclick. Use on() method to bind event handlers.

Event name Description
click() The jQuery click() is an inbuilt method that starts the click event or attaches a function to run when a click event occurs.
dblclick() The jQuery dblclick() is an inbuilt method that is used to trigger the double-click event to occur.
moueenter() This is an inbuilt method that works when the mouse pointer moves over the selected element.
mouseleave() This is an inbuilt method that works when the mouse pointer leaves the selected element.
mouseup() Occurs when any mouse button is released on an element.
contextmenu() Occurs when the right mouse button is clicked on an element, opening the context menu.
mouseover() The event occurs when the pointer is moved onto an element, or onto one of its children.
mouseout() The event occurs when a user moves the mouse pointer out of an element, or out of one of its children.

jQuery Keyboard Events

jQuery Keyboard events handle interactions with the keyboard, like keypress, keyup, keydown. Use on() method to bind event handlers.

Keyboard events Description
keypress() The jQuery keypress() method triggers the keypress event whenever the browser registers a keyboard input.
keydown() This is used to trigger the key-down event whenever the User presses a key on the keyboard.
keyup() This is used to trigger the keyup event whenever the User releases a key from the keyboard.

jQuery Document/ Window Events

jQuery Document/Window events handle interactions with the document or window.

Document events Description
load() load is a document event that triggers when the entire page and its resources have loaded.
resize() resize is a window event that triggers when the window is resized.
scroll() The jQuery scroll() is an inbuilt method that is used to user scroll in the specified element.
unload() The unload is a window event that triggers when the page unloads.

jQuery Form Event

jQuery Form event handles form-related interactions like submit etc. Use on() method to bind event handlers to form elements.

Event name Description
Submit() Form submission event triggered when a user submits a form on a web page.
Change() Event-triggered when an element’s value changes (e.g., input, select).
focus() Event fired when an element gains focus (e.g., input, textarea).
blur() The event is fired when an element loses focus.


Previous Article
Next Article

Similar Reads

How to handle events in dynamically created elements in jQuery ?
When we want to bind any event to an element, normally we could directly bind to any event of each element using the on() method. Example 1: This example using jQuery on() method to add paragraph element dynamically. &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; How to handle events in dynamically created elements in jQuery? &lt;/ti
2 min read
jQuery Mouse Events
This article will explain different mouse events occurring based on mouse positions on a particular HTML element. Mouse Events in jQuery: mouseenter and mouseleave mouseup and mousedown mouseover and mouseout mouseenter and mouseleave: The mouseenter event occurs when the mouse is placed over the HTML element and mouseleave event occurs when the mo
2 min read
How to use jQuery touch events plugin for mobiles ?
In this article, we will learn how to handle various touch events for mobile user interface designing using the jQuery Touch Events plugin which is completely based on JavaScript. These are additional events that can be used with the jQuery which are also compatible with desktop applications as well as mobile web apps. Please download the required
3 min read
jQuery Mobile Collapsible collapse Events
jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Collapsible collapse event to trigger when a collapsible widget is collapsed. Syntax: Initialize the collapsible with the collapse callback specified: $( ".select
1 min read
jQuery Mobile Collapsible expand Events
jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Collapsible expand event to trigger when a collapsible widget is expanded. Syntax: Initialize the collapsible with the expand callback specified: $( ".selector" )
2 min read
jQuery Mobile Collapsible create Events
jQuery Mobile is a web-based technology and great building UI interfaces for the webpages that can be used to make responsive content for websites that can be accessed on all types of smartphones, tablets, and desktops. In this article, we will be using the jQuery Mobile Collapsible create events to trigger when a collapsible widget is created. Syn
2 min read
jQuery UI Resizable stop Events
jQuery UI is a web-based technology and consists of GUI widgets, visual effects, and themes implemented using the jQuery, JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to add widgets easily. In this article, we are going to
2 min read
jQuery UI Resizable start Events
jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Resizable start event is triggered when the resize operation is started. Syntax: Initializing the resizable start event. $( ".selector" ).resizable({ start: function( ev
2 min read
jQuery UI Resizable resize Events
jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Resizable resize event is triggered during the resize operation. Syntax: Initializing the resizable resize event. $( ".selector" ).resizable({ resize: function( event, u
2 min read
jQuery UI Resizable create Events
jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Resizable create event is triggered when the resizable is created. Syntax: Initializing the resizable create event. $( ".selector" ).resizable({ create: function( event,
2 min read
three90RightbarBannerImg