WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the different between this (http://pastebin.com/PX0YB0hy) and (http://pastebin.com/VBqiMHVQ) for JQuery Masonry.

Why does the first one work and the second one doesn't.

In both cases I used wp_enqueue_script to add the script.


share|improve this question
And - did that explain the difference? – Systembolaget Aug 23 '12 at 20:36
Yes it did. Thanks! – JK Thng Aug 28 '12 at 11:23
Glad it helped. These three functions are our best jQuery friends... – Systembolaget Aug 28 '12 at 12:58
up vote 2 down vote accepted

This executes, when the DOM has been constructed, before all content has been loaded

$(document).ready(function(){ ... });
$(function(){...}); // short form

This executes, when all content has been loaded

$(window).load(function(){ ... });

This executes immediately, when it is first encountered by the browser

(function(){ ... })();

The latter is known as a self-executing anonymous function, which is very handy, but not here, because no content or not the right content may have been loaded when it self-executes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.