Recently I begin to study the jquery, I feel confused how jquery library implement the $, I walked through the jquery source code and still cannot understand it.
Why is $( “#xid” ) equivalent to getElementById(“xid”)?
Could you please explain $ for me according to the source code of jquery?
thanks.
Quick Answer
The
$is simply a function name. To explain in simple words, it just mimics the DOM Selector.Where the selector is something like
#hello, theselector[0]depicts the first character, which is a#in this case. The#is used to denote an ID of an element. Similarly,.is used to denote a class name and others are for tags. Hope it is clear.