Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
866 views
Welcome To Ask or Share your Answers For Others

1 Answer

$ 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:

  1. register a document.ready handler - $(myfunc)
  2. act as a selector - $('#myid')
  3. construct elements - $('<div>')
  4. return an empty object - $()

$ 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...