user3520540
user3520540

Reputation: 35

What is this jQuery function call?

The following is an implementation code from a free jquery gallery I am trying to implement.

<script>
jQuery(function(){
  jQuery('#camera_wrap_2').camera({
    height: '400px',
    loader: 'bar',
    pagination: false,
    thumbnails: true
  });
});
</script>

What does this code do? I looked up methods to declare a function with jQuery, and none starts with

jQuery(function(){
  jQuery('#camera_wrap_2').camera({

If anyone can explain what this does and point me to a resource on declaring such functions, i would be eternally grateful. Googling jQuery(function(){ did not really work.

Moreover, This code only worked with the jquery file included - which is jquery.min.js v.1.7.1 and jquery.mobile.customized.min.js

When I used the jquery.min.js v.2.1.1 included with foundations 5, it produced an error in the jquery.mobile.customized.min.js

My guess is that the author had customized his mobile.js to work only with the specific jquery? I don't understand how that would happen though, even deprecated functions usually work.

Upvotes: 1

Views: 90

Answers (2)

codecracker
codecracker

Reputation: 33

I just want to add ...

Please to refer : jQuery-Library Source Code

In that library look at bottom-most comment section

// Expose jQuery to the global object

window.jQuery = window.$ = jQuery;

// Expose jQuery as an AMD module, but only for AMD loaders that...
...

...

...

So you will get to know that window.jQuery is equivalent to jQuery which is equivalent to window.$ which is also equivalent to $.So use any one!!!

therefore, window.jQuery=jQuery=window.$=$

Upvotes: 1

Todd
Todd

Reputation: 5454

$(function() {}) is shorthand for $(document).ready(function())

NOTE: that is the same as:

jQuery(function() {}) is shorthand for jQuery(document).ready(function())

The $ is an alias for the jQuery object

it waits for all elements to be added to the DOM, so you can be sure they exist before calling methods upon them

Upvotes: 2

Related Questions