Skip to content
  • Quizes
  • QStack
  • Blog
  • pinterest
  • instagram
  • twitter
  • linkedin
  • facebook
W3 Coding Schools
  • Home
  • HTML
    • HTML Introduction
    • HTML Editors
    • Fundamentals of HTML
    • Elements of HTML
    • HTML Attributes
    • HTML Headings
    • HTML Paragraphs
    • HTML Style Attribute
    • HTML Text Formatting
    • HTML Phrase Tags
    • HTML Comments
    • HTML with CSS
    • HTML Links
    • HTML Images
    • HTML Tables
    • HTML Lists
    • HTML Blocks
    • HTML Class Attribute
    • HTML Id Attribute
    • HTML Iframes
    • HTML JavaScript
    • HTML File Paths
    • HTML Head
    • Computer Code Elements
    • HTML Entities
    • HTML Charset
    • HTML URL Encode
    • HTML and XHTML
    • HTML Layouts
    • HTML Forms
    • HTML Form Elements
    • HTML Form Input Types
    • HTML Input Attributes
    • HTML5 Introduction
    • HTML5 New Elements
    • Semantic Elements
    • HTML5 Migration
    • Style Guide
    • HTML Canvas
  • CSS
    • CSS Introduction
    • CSS Syntax and CSS Comments
    • CSS Selectors
    • How to add CSS to a Webpage
    • CSS Color Basics
    • CSS Background Properties
    • CSS Border Properties
    • CSS Margin and Padding Properties
    • CSS Height and Width properties
    • CSS Box Model
    • CSS Outline Properties
    • CSS Fonts
    • CSS Text
    • How To Add Icons
    • CSS Links
    • CSS List-Style
    • CSS Tables
    • CSS Display Property
    • CSS Position Property
    • CSS Overflow Property
    • CSS max-width Property
    • CSS Float and Clear Properties
    • CSS Alignment
    • CSS inline-block
    • CSS Combinators
    • CSS Pseudo Classes
    • CSS Pseudo Elements
    • CSS Opacity
    • CSS Navigation Bar
    • CSS Dropdowns
    • CSS Image Gallery
    • CSS Image Sprites
    • CSS Attribute Selector
    • CSS Styling Forms
    • CSS Counters
    • CSS Units
    • CSS Specificity
    • CSS Website Layout
    • CSS Rounded Corners
    • CSS Border Image Property
    • CSS Multiple Backgrounds
    • CSS Gradient
    • CSS Shadow Effects
    • CSS Text Effects
    • CSS Web Fonts
    • CSS 2D Transforms
  • Bootstrap 4
    • Bootstrap 4 – Introduction
    • Bootstrap versions
    • Bootstrap 4 Layout
    • Bootstrap 3 Vs Bootstrap 4
    • Bootstrap 4 Grid System
    • Bootstrap 4 Typography
    • Bootstrap 4 Colors
    • Bootstrap 4 Images
    • Bootstrap 4 Tables
    • Bootstrap 4 Jumbotron
    • Bootstrap 4 Figures
    • Bootstrap 4 Alerts
    • Bootstrap 4 Buttons
    • Bootstrap 4 Button Group
    • Bootstrap 4 Badges
    • Bootstrap 4 Spinners
    • Bootstrap 4 Progress Bars
    • Bootstrap 4 Pagination
    • Bootstrap 4 Breadcrumbs
    • Bootstrap 4 List Groups
    • Bootstrap 4 Cards
  • jQuery
    • jQuery Introduction
    • jQuery Download
    • jQuery Selectors
    • jQuery Event Methods
    • jQuery Hide/Show Effects
    • jQuery Fading Effects
    • jQuery Sliding Effects
    • jQuery Animation
    • jQuery Stop and Callback
    • jQuery Get and Set Methods
    • jQuery Chaining
    • jQuery Add
    • jQuery Remove
    • jQuery CSS Classes
    • jQuery Style Properties
    • jQuery Dimensions
    • jQuery Traversing
    • jQuery Ancestors
    • jQuery Descendants
    • jQuery Siblings
  • Javascript
    • JS Introduction
    • JS Where to Put
    • JavaScript Syntax
    • JavaScript Comments
    • JavaScript Variables
    • JavaScript Data Types
    • JavaScript Operators
    • JavaScript Events
    • JavaScript Strings
    • JavaScript Numbers
  • php
    • PHP Introduction
    • Install PHP
    • PHP Syntax and Comments
    • PHP Variables
    • PHP Constants
    • PHP Echo and Print
    • PHP Data Types
    • PHP Strings
    • PHP Operators
    • PHP $ and $$ Variables
  • WordPress
    • WordPress Introduction
    • WordPress History
    • WordPress.com vs WordPress.org
    • How to Install WordPress
    • WordPress Dashboard
    • How to Create a WordPress Website
    • WordPress Posts
    • WordPress Pages
    • WordPress Posts vs Pages
    • WordPress Categories
  • SEO
    • SEO Introduction
    • SEO Tactics and Methods
    • SEO Relevant Filenames
    • SEO Domain Name
    • Website Design and SEO
    • SEO Keywords
    • Meta Tags Optimization
    • Title Tag Optimization
    • Anchor Text Optimization
    • Content Optimization
  • Android
    • Android Introduction
    • Android History and Versions
    • Android Architecture
    • Android Environment Setup
    • Android Application Components
    • Hello World Application
    • Android Activities
  • iOS
    • iOS Introduction
    • iOS Environment Setup
    • iOS Architecture

You Are Here

  • Home
  • Learn jQuery
  • jQuery Event Methods

Topics

  • jQuery Siblings
  • jQuery Descendants
  • jQuery Ancestors
  • jQuery Traversing
  • jQuery Dimensions
  • jQuery Style Properties
  • jQuery CSS Classes
  • jQuery Remove
  • jQuery Add
  • jQuery Chaining
  • jQuery Get and Set Methods
  • jQuery Stop and Callback
  • jQuery Animation
  • jQuery Sliding Effects
  • jQuery Fading Effects
  • jQuery Hide/Show Effects
  • jQuery Event Methods
  • jQuery Selectors
  • jQuery Download
  • jQuery Introduction

Oct Champs & Prizes

  • 1. Pooja Ladda
  • 2. Manjali Kuldharan
  • 3. Pranali Surawar
  • 4. Anjali Kulkarni
  • 5. Vishal Deshmukh

Recent Posts

  • HTML Media
  • jQuery Siblings
  • Bootstrap 4 Cards
  • jQuery Descendants
  • jQuery Ancestors

jQuery Event Methods

What are jQuery Events?

In most of the web applications, the user performs some operation to do some actions. Events are actions that can be detected by your web application when the user performs some operation. The jQuery event method registers an event handler when the user interacts with the web pages.
For e.g, the user clicks on the save button to save the webpage. Here in this example, clicking on the button is user action which triggers click event and the click event function(handler) saves data.

Following are some examples of events:

  • A mouse click
  • A web page loading
  • Taking mouse over an element
  • Submitting an HTML form
  • A keystroke on your keyboard, etc.

Following are some common DOM events:

Category jQuery Method DOM Event
Form events blur onblur
change onchange
focus onfocus
focusin onfocusin
submit onsubmit
select onselect
Keyboard events keydown onkeydown
keypress onkeypress
keyup onkeyup
Mouse events click onclick
dblclick ondblclick
mousedown onmousedown
mouseenter onmouseenter
mouseleave onmouseleave
mousemove onmousemove
mouseout onmouseout
mouseover onmouseover
mouseup onmouseup
Browser events Error onerror()
Resize onresize
Scroll onscroll
Document loading Load onload
Unload onunload

jQuery Syntax for Event Methods:

The DOM events have an equivalent jQuery method. If you want to assign a click event to all <h2> elements on a page, you can do this:
$("h2").click();
The next step defines what should happen when the event occurs, you must pass a function to the event.
$("h2").click(function(){
// action you want to perform
});

Commonly Used jQuery Event Methods:

$(document).ready():

The $(document).ready() function will execute jQuery functions after web page is fully ready. This $(document).ready() event is already explained in the jQuery Download and Syntax topic.
<script>
$(document).ready(function(){
// your jquery code
})
</script>

click():

The jQuery click event occurs when the user clicks on an HTML element. The click() method in jQuery is used to trigger the click event. For example, $(“div”).click() will trigger the click event when a div is clicked on a document (a web page). We can attach a function to the click() method to run the function when a click event occurs, this way we can run a piece of code every time the click event is triggered.

Example:

$("div").click(function(){
$(this).hide();
});
Try it

dblclick():

The jQuery dblclick() method attaches a double click event handler function to an HTML element. This event handler function executes when the user double clicks on the HTML element.

Example:

$("div").dblclick(function(){
$(this).hide();
});
Try it

mouseenter():

The jQuery mouseenter() method attaches the mouse enter event handler function to an HTML element. This event handler function executes when the mouse pointer enters the attached HTML element.

Example:

$("#h2").mouseenter(function(){
alert("You entered h2!");
});
Try it

mouseleave():

The jQuery mouseleave() method attaches mouse leave event handler function to HTML elements. This mouse leave event is triggered when the mouse pointer leaves the HTML element. When the mouse leave event is triggered, the associated event handler function executes.

Example:

$("#h2").mouseleave(function(){
alert("Mouse pointer leaves the header element!");
});
Try it

mousedown():

The jQuery mousedown() method associates an event handler function to the HTML elements. This event handler function is executed when any of the mouse button (left, right or middle) is pressed down on an HTML element.

Example:

$("#h2").mousedown(function(){
alert("Mouse down over h2!");
});
Try it

mouseup():

The jQuery mouseup() method attaches an event handler function to the HTML elements. This event handler function is executed when the any of the mouse button (left, right or middle) is released, while the mouse pointer is over the HTML element.

Example:

$("#h2").mouseup(function(){
alert("Mouse up over h2!");
});
Try it

hover():

The jQuery hover() method is a combination of mouseenter() and mouseleave() methods. The hover() method attaches an HTML element to two of the event handler functions, the first function executes when the mouse pointer enters the HTML element and the second function executes when the mouse pointer leaves the HTML element.

Example:

$("#h2").hover(function(){
alert("You entered h2!");
},
function(){
alert("You now leave h2!");
});
Try it

focus():

The jQuery focus() method attaches an event handler function to HTML elements. This event handler function executes when a form field gets focus.

Example:

$("input").focus(function(){
$(this).css("background-color", "#ff5722");
});
Try it

blur():

The jQuery blur() method attaches an event handler function to HTML elements. This function executes when a form field loses focus. This method works just opposite to the focus() method. The difference between focus() and blur() method is that the focus event is triggered when a form field gets focus while blur event is triggered when a form field loses focus.

Example:

$("input").blur(function(){
$(this).css("background-color", "#f7f7f7");
});
Try it

Post navigation

jQuery Selectors
jQuery Hide/Show Effects

Ask a Question Cancel reply

Your email address will not be published. Required fields are marked *

W3 CODING SCHOOLS © Copyright 2019-20
Privacy policy   Terms of use

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok