?
Solved

adv jquery

Posted on 2012-09-18
6
Medium Priority
?
229 Views
Last Modified: 2012-09-19
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..
0
Comment
Question by:Moizsaif123
  • 3
  • 2
6 Comments
 
LVL 7

Assisted Solution

by:aplusexpert
aplusexpert earned 460 total points
ID: 38412591
0
 
LVL 83

Expert Comment

by:leakim971
ID: 38413378
> 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
 
LVL 4

Author Comment

by:Moizsaif123
ID: 38413400
>> 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 83

Accepted Solution

by:
leakim971 earned 460 total points
ID: 38413436
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
 
LVL 4

Author Comment

by:Moizsaif123
ID: 38413730
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
 
LVL 83

Expert Comment

by:leakim971
ID: 38413835
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question