-1

Why we use this Jquery(document).ready() instead $(document).ready()

Actually this both are giving same result, but what the reason for using one of the, normally lost of people are using $(document).ready() instead above listed

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
  • No one use the above, unless you removed the extra dot. – xdazz Apr 24 '14 at 07:30
  • 3
    `$` is an alias for `jQuery` so you can use either one. – jfriend00 Apr 24 '14 at 07:31
  • here all things are explained in detail plz refer this link ([here][1]) [1]: http://stackoverflow.com/questions/8396407/jquery-what-are-differences-between-document-ready-and-window-load – Gaurang s Apr 24 '14 at 07:51

6 Answers6

3

this is usually to avoid conflict with other libraries that could be using the "$" sign.

hekigan
  • 134
  • 2
  • 11
2

Well you may have more JavaScript libraries than only jQuery, and some of them may use the dollar sign $ too. If you use jQuery instead, you have more guaranted, that in this variable will be jQuery instance.

Tomáš Blatný
  • 892
  • 6
  • 20
1

This is to prevent namespace collision. The dollar sign might be used by other JavaScript libraries. For this jQuery also provides the jquery.noConflict() function.

sidneydobber
  • 2,790
  • 1
  • 23
  • 32
1

its a short hand syntax.See more at http://try.jquery.com/levels/1/sections/2

Ajay
  • 2,022
  • 19
  • 33
1

$ and jQuery both point to the window.jQuery object, so they are one and the same. the reason some scripts use jQuery instead of $ is to prevent conflicts with other libraries such as prototype or different versions of jquery which both also use the $ variable.

Tuhin
  • 3,335
  • 2
  • 16
  • 27
1

to get full compatibility. For example in Wordpress CMS, jquery is built in, but not using $. so it's safer to create plugins using jQuery(function($){});. Take note that $ added as a parameter so that you can use it inside the ready.

thedjaney
  • 1,126
  • 2
  • 10
  • 28