<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>jQuery</title>
        <link>http://geekswithblogs.net/sankarsan/category/9909.aspx</link>
        <description>jQuery</description>
        <language>en-US</language>
        <copyright>sankarsan</copyright>
        <managingEditor>sankarsan_b@yahoo.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Journey with jQuery - Part I</title>
            <link>http://geekswithblogs.net/sankarsan/archive/2009/04/03/journey-with-jquery---part-i.aspx</link>
            <description>&lt;p&gt;My journey with jQuery has actually began last month when along with ASP.NET MVC I started exploring the different features provided by jQuery and related plugins.I am simple amazed at the overall design of jQuery core and also by functionalities provided by the various plugins built around jQuery.I am planing to write a series of posts with my observations on jQuery and this happens to be the first in that series.&lt;/p&gt;
&lt;p&gt;In this post I will discuss about the magical &lt;font color="#800000"&gt;&lt;em&gt;ready()&lt;/em&gt;&lt;/font&gt; function in jQuery.I always used to put all the scripts that needs to be executed when the page is loaded in the &lt;em&gt;&lt;font color="#800000"&gt;onload&lt;/font&gt;&lt;/em&gt; event of the &amp;lt;BODY&amp;gt; tag or set it using &lt;font color="#800000"&gt;&lt;em&gt;window.onload &lt;/em&gt;&lt;/font&gt;as shown below &lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;&amp;lt;script type="text/javascript"&amp;gt; &lt;br /&gt;
     function showAlert() { &lt;br /&gt;
         alert('Hi'); &lt;br /&gt;
     } &lt;br /&gt;
     window.onload = showAlert; &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This script will execute when the entire page has finished loading including all the images.jQuery exposes a more sophisticated &lt;em&gt;&lt;font color="#800000"&gt;ready&lt;/font&gt;&lt;/em&gt; event to do the same job as shown below:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;&amp;lt;script type="text/javascript" src="./jquery-1.3.2.js"&amp;gt;&amp;lt;/script&amp;gt; &lt;br /&gt;
&amp;lt;script type="text/javascript"&amp;gt; &lt;br /&gt;
    $(document).&lt;strong&gt;ready&lt;/strong&gt;(function() { &lt;br /&gt;
            alert('Hi'); &lt;br /&gt;
    }); &lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This ready checks whether DOM has loaded completely or not.If it is loaded the function is executed else it is pushed to the wait queue as shown below:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;ready: function(fn) { &lt;br /&gt;
    // Attach the listeners &lt;br /&gt;
    bindReady(); &lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;&lt;strong&gt;    // If the DOM is already ready&lt;/strong&gt; &lt;br /&gt;
    if ( jQuery.isReady ) &lt;br /&gt;
        &lt;strong&gt;// Execute the function immediately &lt;br /&gt;
&lt;/strong&gt;        fn.call( document, jQuery ); &lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt; &lt;strong&gt;   // Otherwise, remember the function for later &lt;br /&gt;
&lt;/strong&gt;    else &lt;br /&gt;
      &lt;strong&gt;  // Add the function to the wait list &lt;br /&gt;
&lt;/strong&gt;        jQuery.readyList.push( fn ); &lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;    return this; &lt;br /&gt;
},&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For Internet Explorer it checks the loading status of the DOM using the &lt;font color="#800000"&gt;&lt;em&gt;onreadystatechange&lt;/em&gt;&lt;/font&gt; event and &lt;font color="#800000"&gt;&lt;em&gt;readyStatus&lt;/em&gt;&lt;/font&gt; property of the document object as shown below:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;document.attachEvent("&lt;strong&gt;onreadystatechange&lt;/strong&gt;", function(){ &lt;br /&gt;
    if ( document.&lt;strong&gt;readyState&lt;/strong&gt; === "complete" ) { &lt;br /&gt;
        document.detachEvent( "onreadystatechange", arguments.callee ); &lt;br /&gt;
        jQuery.ready();&lt;/font&gt;&lt;/em&gt; &lt;/p&gt;
&lt;p&gt;So this is in short that's all I had to say about ready event in jQuery.This is the most important function of jQuery and we will use in the samples of the next posts to come.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/sankarsan/aggbug/130733.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>sankarsan</dc:creator>
            <guid>http://geekswithblogs.net/sankarsan/archive/2009/04/03/journey-with-jquery---part-i.aspx</guid>
            <pubDate>Sat, 04 Apr 2009 00:39:32 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/sankarsan/comments/130733.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/sankarsan/archive/2009/04/03/journey-with-jquery---part-i.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/sankarsan/comments/commentRss/130733.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
