adv jquery

In Jquery I understand that the jq code is written and executed before the html page is loaded. Is that correct? so the javascript code is run after the jq.

What is the advantage of this. Can there be an example..
LVL 4
Moizsaif123Asked:
Who is Participating?
 
leakim971PluritechnicianCommented:
again jQuery is Javascript.

to manipulate body content, so element like like <p> and <a>
you need to wait the loading of the body, its element... else the box is empty, you can't play with the toys inside

most of time we use :
window.onload = function() {
   // now we can play with body content with pure javascript code or jQuery
}

Open in new window


or with jQuery :
$(document).ready(function() {
   // now we can play with body content with pure javascript code or jQuery
})

Open in new window

http://web.enavu.com/daily-tip/daily-tip-difference-between-document-ready-and-window-load-in-jquery/
0
 
aplusexpertCommented:
0
 
leakim971PluritechnicianCommented:
> Is that correct?

No, if you put you jQuery inside the head section, it will run before loading of the body content.

Else check the links provided by aplusexpert
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Moizsaif123Author Commented:
>> it will run before loading of the body content.

is this why jq can access or manipulate html elements like <p> and <a> tags whereas javascript cannot...
0
 
Moizsaif123Author Commented:
this is just for reference purpose....


 window.onload = function(){ alert("welcome"); }


>>
Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code.

To circumvent both problems, jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event:

 $(document).ready(function(){
   // Your code here
 });
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.