Best way to work with jQuery with $ in no-conflict mode
-
Hi everybody!
The problem of using $ with jQuery in no-conflict mode was discused in a lot of questions and in the WordPress documentation. It seems a good solution to use following lines:
(function($) { // $() will work as an alias for jQuery() inside of this function })(jQuery);
I wonder if it function could be used as wrapper for all the jQuery code, and if we could have inside our “document ready” function, but also our “window load” and “resize” listeners, as follows:
(function($) { /* trigger when page is ready */ $(document).ready(function (){ functionToCall(); }); function functionToCall() { // some code here } $(window).load(function() { // functions here, triggered when page is loaded }); $(window).resize(function() { // resize functions here }); })(jQuery);
- The topic ‘Best way to work with jQuery with $ in no-conflict mode’ is closed to new replies.