The magic of the $
In jQuery, the $ character is the shortcut to the jQuery factory,
meaning that it provides access to the jQuery object and all of the
power that jQuery offers. You can use the $ to access global objects and
functions, and, more commonly, elements and other components in the
DOM.
The first operation you'll typically perform in any page that uses jQuery is to register a
document.ready
event handler. The document.ready
event handler executes after everything on the page has loaded, ensuring that the entire DOM is now in memory, and the jQuery library is now available.
There are a couple of ways to register this event handler. The first is to access the
document
object in jQuery, and register an event handler with the jQuery ready
event.
$(document).ready(function() {
// code here
});
Because registering an event handler with jQuery is so common, jQuery provides a shortcut. Simply passing a function into the constructor will register that function as the event handler for
document.load
.
$(function() {
// code here
});
Both of the code blocks above are semantically identical.
Ref: https://courses.edx.org/courses/course-v1:Microsoft+DEV208x+2T2016/courseware/427434212cbf4237a9a34a256ac2bbd2/7a171409695b45fcaa4298f48c4ea1c2/?child=first
ReplyDelete