how jquery works?

by Developer 17. January 2010 08:17

The execution of jQuery is not the same way as normal javascript execution. Javascript will execute whenever it loads irrespective of total HTML page loaded or not.

 

But, jQuery provides different functionality. The code inside the jQuery will execute after HTML page load completion.

 

Here I am giving simple example where you can compare the execution of jQuery with normal javascript execution.

I included the jQuery Framework file jQuery.js.

 

<html>
   <head>
   <title>This is first jquery example</title>
   <script type="text/javascript" src="jquery.js"></script>
   <script type="text/javascript">
        $(document).ready(function() {
          alert('This is from head tag using jquery document ready event');
       });
         alert('This is from head tag with out using jquery document ready event');
   </script>
  </head>
  <body>
  <script type="text/javascript">
     alert('This is from body tag');
  </script>
  </body>
</html>

 

In the above code, we have three javascript alerts. First one is in <body> tag, second one is inside the <head> tag and third one is inside the <head> tag with jQuery functionality.

 

Whenever you open this HTML file in browser, you will get first alert as  "This is from head tag with out using jquery document ready event", second as "This is from body tag"  and after page load completion you will get thrd alert as "This is from head tag using jquery document ready event" which is from jQuery.

 

That means, whenever page loads first javascript code in <head>  tag will execute. But jQuery as ready function, it will wait untill page load completion. So, normal javascript code in <head>  tag will execute first after that code in <body> tag will executes. After page load completion, jQuery code will execute.

 

Conclusion:

From the above, jQuery is not only light weight and also it will wait untill page loads. So, what ever you write code using jQuery that will execute after page loads.

 

Download source code:  first jQuery Exp.zip (35.60 kb)

Comments

4/4/2010 6:37:04 PM #

CHAD

Interesting blog, not like the others! It would be nice if more blogs nowadays had good information like this!

CHAD

4/11/2010 3:47:24 PM #

ROSLYN

You should really moderate the comments here. So many spammy comments. WTF are all these people saying 'I love your post' etc. Doesn't necessarily add value to your blog... does it?

ROSLYN

4/15/2010 2:34:16 PM #

Rapidshare Search

I would like to thank you for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

Rapidshare Search

5/5/2010 3:52:27 AM #

I believe that this blog has interesting content overall.

5/5/2010 4:28:28 AM #

After having read a lot of useless posts, this blog helps me a lot.

6/29/2010 5:20:53 AM #

Proven Penis Enlargement

Thanks again for providing good content yet yet again. Definitely a pro-blogger if I�ve observed a single.

Proven Penis Enlargement

6/30/2010 9:36:46 AM #

Proven Penis Enlargement

Hey � I�m talking to a lot of webmasters to locate out if they have heard whatever in regards to the substantial blog page page engine change that is in the works? With WP releasing 3 highly shortly, the word on the street is that BE is planning to make a whole terrific deal of alterations that glimpse like WP adjustments. Shoot me an email will need to you happen to listen to anything.

Proven Penis Enlargement

7/9/2010 6:20:36 AM #

male enhancement

There's nothing much better than performing at your peak. I love it, as well as so does my girl.

male enhancement

9/1/2010 7:02:56 PM #

viagra alternative

I dont normally comment on blogs but i just wanted to show my apreaciation well done all

viagra alternative

Add comment




  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading



Page List

    Tag cloud