0

I have a script which looks like this

  $(function(){

  ... Jquery Code in Here

  });

and I want to wrap it to make it compatible with WordPress. Do I have to do ...

(function($){

  $(function(){

  ... Jquery Code in Here

  });

})(this.jQuery);

It works but it seems like there might be a more concise version. Is there?

1

1 Answer 1

2

use "jQuery" instead of "$":

jQuery(document).ready(function(){

    jQuery("#mydiv").addClass('myclass'); //or some function here

});

...as found in the codex page.

1
  • Sorry I wasn't fully clear in my question obviously ... I did actually already know how to do this however the part I didn't know ( I now realise, apologies ) was whether or not I could actually REPLACE ALL of the code in my quesiton with ... (from your example) jQuery(document).ready(function(){ ... my code here }); or to put it another way I'm not entirely sure of whether I can replace $(function(){ }); with a no conflict wrapper ... I suppose I'm just confused about all these wrappers and document.ready and self invoking anonymous functions etc as I find them all very similar Commented Nov 15, 2013 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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