-3

I recently noticed in a JavaScript recently that there was a (jQuery) included at the end of the script. What does it mean and What does it do ?

(function($) {
    //  code here
    ................
})(jQuery);
Gopinagh.R
  • 4,458
  • 4
  • 43
  • 58

4 Answers4

8

It would look something like this:

(function($){
  //your code here
})(jQuery)

It is to make sure that the dollar sign ($) refers to the jQuery object. Sometimes other libraries might change it.

tckmn
  • 52,184
  • 22
  • 101
  • 145
0

If you're asking what jQuery itself is:

http://jquery.com/

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.

Andy
  • 28,587
  • 9
  • 37
  • 58
0

Probably you've seen something like this -

(function(anArgument) {
    // lots of code
    ................
})(jQuery);

What is does is that, it creates an anonymous function with one argument and then immediately invokes it with the jQuery object as its parameter.

You'll learn more about it if you go to this post.

Community
  • 1
  • 1
MD Sayem Ahmed
  • 26,780
  • 23
  • 104
  • 174
0

The JQuery object :)

From the JQuery doc:

By default, jQuery uses "$" as a shortcut for "jQuery"

So, using $("#id") or jQuery("#id") is the same

chandresh_cool
  • 11,444
  • 2
  • 25
  • 44