What does $ do when using jQuery?

I am reading JavaScript and jQuery, a skipped manual

and they start with this snippet:

$(document).ready(function(){}); 

I know that function(){} is an anonymous function, and this document is an object with properties that I can set / read, and that ready () is a jQuery function defined in the library, but I don't know what the rest of The syntax for and is not explained in the book.

In particular,

 $(document) 

Can someone explain what this means, or give me a link? Also, someone said that you can identify jQuery with just that, is that true?

+6
source share
7 answers

$(document) wraps a jQuery instance around a document object. ( $ is just an alias for jQuery . Therefore, the return value of $(document) is an instance of jQuery that has ready on it.

+4
source

This is a synonym for jquery () function:

http://api.jquery.com/jQuery/

+2
source

$ is a shortcut for a jQuery object. All methods in the jQuery library are part of the jQuery object.

$(selector) is the same as writing 'jQuery (selector) `

+1
source

$ operators before jquery should distinguish between standard javascript and jquery. But other frameworks can also use the dollar sign, so sometimes you will see jQuery (document) so that they don’t conflict. It can also be tuned to anything, even $ jq, etc. All he does is say that your code uses the framework functions instead of the standard javascript.

+1
source

$ is a synonym for jQuery, and what it does is described here: http://api.jquery.com/jQuery/

+1
source

$ is an alias (short-hand) for the jQuery variable, which is a security object that stores all jQuery functions.

$(document) takes your current window.document (part of window. often skipped when accessing window properties) and passes it to the jQuery $() constructor, and then attaches the event handler to the ready event, which performs an anonymous function passed as a callback .

+1
source

$ is just a selector for jquery. You pretty much say that the following after "$" is part of the jquery library.

Be careful because some other javascript libraries use the same selector.

-3
source

Source: https://habr.com/ru/post/911693/


All Articles