[jQuery] Re: calling style
Difference between the two code? On Nov 6, 12:36 pm, Satyakaran [EMAIL PROTECTED] wrote: function load() { //jQuery(function($) { $(#div1).load(starterkit.html); //}); } OR function load() { jQuery(function($) { $(#div1).load(starterkit.html); }); } Can you tell me what is the difference between the two. I know both works. So, which one should I use. I am talking about the commented code on first snippet. Thanks!
[jQuery] Re: calling style
he's commented out the jquery call out. All you would need is this; jQuery(function() { $(#div1).load(starterkit.html); }); Satyakaran wrote: Difference between the two code? On Nov 6, 12:36 pm, Satyakaran [EMAIL PROTECTED] wrote: function load() { //jQuery(function($) { $(#div1).load(starterkit.html); //}); } OR function load() { jQuery(function($) { $(#div1).load(starterkit.html); }); } Can you tell me what is the difference between the two. I know both works. So, which one should I use. I am talking about the commented code on first snippet. Thanks!
[jQuery] Re: calling style
The difference is that the commented out version assumed that jQuery is the only JS library, as the $ function is used in other libraries, such as mootools and Prototype, so the jQuery(function($) { }) stops any conflicts Rik 2008/11/6 Liam Potter [EMAIL PROTECTED]: he's commented out the jquery call out. All you would need is this; jQuery(function() { $(#div1).load(starterkit.html); }); Satyakaran wrote: Difference between the two code? On Nov 6, 12:36 pm, Satyakaran [EMAIL PROTECTED] wrote: function load() { //jQuery(function($) { $(#div1).load(starterkit.html); //}); } OR function load() { jQuery(function($) { $(#div1).load(starterkit.html); }); } Can you tell me what is the difference between the two. I know both works. So, which one should I use. I am talking about the commented code on first snippet. Thanks! -- Rik Lomas http://rikrikrik.com
[jQuery] Re: calling style
On Thu, Nov 6, 2008 at 2:36 AM, Satyakaran [EMAIL PROTECTED] wrote: function load() { //jQuery(function($) { $(#div1).load(starterkit.html); //}); } This one calls the .load() immediately. OR function load() { jQuery(function($) { $(#div1).load(starterkit.html); }); } This one waits to call .load() until the DOM is loaded. This is shorthand syntax for jQuery(document).ready(function($) { ... }); which says call this function I provide as soon the document/DOM is ready. This guarantees that your element #div1 is available for selecting and manipulation. So the difference depends on where your function load() is being called. If it's called after the page is loaded (say, by a button click) there will be no difference. If it's called during the page load (say, in the head) you'll want the latter. For more info see http://docs.jquery.com/How_jQuery_Works#.24.28document.29.ready.28function.28.29.7B.7D.29.3B - Richard