JQuery is a library based on JavaScript.
It is scripting language (mainly for client side).
HTML only supports the web pages which are static. For dynamic operations we cannot do by using Html.
To perform dynamic operation we use scripting language.
Things we have to know before learning JQuery.
· HTML.
· CSS
· JAVASCRIPT
Important JavaScript functions are
document.getElementById(“”)
document.getElementByName(“”)
document.getElementByTagName(“”)
document.getElementByClassName(“”)
What is JQUERY?
Jquery is a light weight cross browser JavaScript library. It is collection of pre- defined functions.
Jquery is the most popular JavaScript library in use today.
It is collection of write less Do More library.
It is released in Jan 2006 at Bar Camp NYC by John Resign.
Bar camp is an international network of user generated conferences primarily focused around technology and the Web.
Jquery greatly simplifies JavaScript Programming.
Jquery is free open source software. Jquery is designed to keep the things easy, simple and reusable.
Jquery syntax is designed to make it easier to navigate a document. Select DOM Element, create animations, handle events and develop Ajax applications.
The official Jquery statement is
“JQUERY is a fast and concise JavaScript library that simplifies html document traversing, event handling, and animating and Ajax interactions for rapid web development.”
Features of Jquery
· DOM element selection functions
· Event Handling
· DOM transversal & Modifications
· CSS Manipulations
· Effects and Animations
· Ajax Interactions
· Cross Browser Support.
If we want an event to work on your page we should call it inside the
$(document).ready ()
Everything inside it will be loaded as soon as DOM is loaded and before the page contents are loaded.
To do this we register a ready event for the document as following.
$(document).ready (function () {
//do something when Dom is ready.
});
$(document).ready ()
Query’s document.ready () method gets called as soon as DOM is ready (means browser has parsed the HTML and built the DOM tree). It is cross browser compatible means behave equally on all browsers.
If your web page has large images, it will not wait for loading of images completely. Hence it may called before page Load () method. We can have multiple document.ready () methods on a web page .
· Best for onetime initialization.
· Called as soon as DOM is ready; may called slightly before than pageLoad().
· Cross browser compatible.
· Unable to re-attach the functionality to elements/controls of the page affected by partial postbacks.
Page_load
pageLoad() method gets called when images and all associated resources of the page have been fully loaded.
Suppose your web page has large size images then until all the images are not fully loaded on the page, pageLoad() method will not called. pageLoad() method is not browser compatible. We can have only one page Load () method on a web page.
Not best for onetime initialization if used with UpdatePanel.
Not Cross browser compatible.
Best to re-attach the functionality to elements/controls of the page affected by partial postbacks with UpdatePanel.
Introducing Update Panel Partial Post Back with page Load () and $(document).ready ().
Since we know, in asp.net update panel gets partially postback to the server. Hence If you are using $(document).ready() and pageLoad() methods on the page, it is mandatory to know the difference between both the methods.
pageLoad() methods is called each and every partial postback of update panel but $(document).ready() is not called each and every partial postback of update panel. $(document).ready() is called only one time (during first time of page loading). Hence code written in $(document).ready() method will not be initialized each and every partial postback.
An ASP.NET AJAX alternative to $(document).ready()
If you are using AJAX on your asp.net web page then you can use Application.add_init() method in place of $(document).ready() for one time initialization
Note that to call Application.add_init, we need to place it after the ScriptManager. This is required because the ScriptManager injects its reference to MicrosoftAjax.js at that location. Attempting to reference the Sys object before Script Maanager will throw a javascript error "sys is undefined".
1. Useful for one time initialization if only ASP.NET AJAX is available.
2. More work required to wire the event up.
3. "sys is undefined" javascript error may occurs if you are not careful.