What is the difference between $() and $.?

javascript, jquery

Solution

`$` is an identifier. It is used as a variable. It has a function assigned to it.

Putting `()` after a function will call it. The function jQuery assigns to it does lots of different things depending on what sort of arguments you pass to it. (It is horribly overloaded). (e.g. if you pass it a function, it will call that function when the document ready event fires. If you pass it a string of HTML, it will create a DOM representation of that HTML and wrap it in a jQuery object. If you pass it a DOM node, it will wrap that node in a jQuery object. If you pass it a CSS selector, it will search the document for matching DOM nodes and wrap them with a jQuery object).

In JavaScript, functions are objects. Objects can have properties. You can access a property on an object via `$.name_of_property`. Those properties can also have functions (or other objects) assigned to them.

Problem

I would like to figure out the difference between using `$()` and `$.` from other developers. As far as my understanding goes, `$()` refers to objects within the `DOM`, but I am not `100%` clear as to how the `$.` works. I have used the `$.` format before, but never understood how it works. For example: `$.each(element, function() {});` or `$.fn` etc... It would be nice to shed some light and clarity on this topic.

Original source

Related problems