jQuery Events Part - I : Document loading Events and Keyboard Events

jQuery events

jQuery basically have following type of events:


Indicates that DOM is fully loaded that mean all controls and it's hierarchy is fully loaded .This is the best place to do all event handling and jacascript/jQuery code manipulations.

Below example shows how to use .ready() in jQuery:

  // Handler for .ready() called.

.load event executes code when page is rendered or a perticular element is rendered. Use this event when code is relies on loaded assests like images.

Below example show .load() in jQuery, and this triggers event when page is fully loaded with all control:

 // Add code here

You may call .load for perticular element when it loads.

<img src="something.png" id="imageDemo"/>

  // Add code here.

Use this event when user navigates away from the page or window.
Below example shows how .unload() works in jQuery:

alert('I am unloading.');


Event on element get triggered when user presses any key on keyboard. If you want keydown event get fired when user start typing in some text box.

Below example shows how .keydown() works in jQuery:
For textbox you can write it like

<input id="keyDownDemo" type="text" value="Hello"/>

alert(Hello jQuery KeyDown Happened.');
Location:Pune Pune, Maharashtra, India


Post a Comment