Could someone take the effort to explain me the difference between $
and $()
in jquery?
I know $()
is shorthand form of $jQuery()
which takes any DOM element and turns it into a jQuery object.
But what I am not sure of is what is $
and how different is it from $()
. Kindly enlighten me.
Thanks heaps, Chaitanya
$
is a function that can be called - $()
.
The behaviour of $()
varies immensely depending on the parameters supplied, although all examples below will return a jQuery
object. It can:
document.ready
handler - $(myfunc)
$('#myid')
$('<div>')
$()
$
is also an object that contains various utility functions $.each
, etc as properties of that object. In this context, it acts like a namespace for those functions.
$ = jQuery
- This is the jQuery object which is used for the jQuery Utilies it contains such as $.Ajax()
or $.each()
Thus var j = $;
will assign the jquery prototype into the variable j
.
$() = jQuery()
- This is a function called from the root jQuery object that is used convert DOM elements to jQuery Objects or get jQuery objects using selectors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With