Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

difference between $ and $() in jQuery

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...