HTML CSS JavaScript jQuery AJAX ASP PHP SQL tutorials, examples for web building ,author kapil kumar: jQuery - Events Handling

Saturday 10 May 2014

jQuery - Events Handling

jQuery - Events Handling


We have the ability to create dynamic web pages by using events. Events are actions that can be detected by your Web Application.
Following are the examples events:
  • A mouse click
  • A web page loading
  • Taking mouse over an element
  • Submitting an HTML form
  • A keystroke on your keyboard
  • etc.
When these events are triggered you can then use a custom function to do pretty much whatever you want with the event. These custom functions call Event Handlers.

Binding event handlers:

Using the jQuery Event Model, we can establish event handlers on DOM elements with the bind()method as follows:
$('div').bind('click', function( event ){
   alert('Hi there!');
});
This code will cause the division element to respond to the click event; when a user clicks inside this division thereafter, the alert will be shown. 
The full syntax of the bind() command is as follows:
selector.bind( eventType[, eventData], handler)

No comments:

Post a Comment