When working with jQuery, how best to write, such as jQuery.ajax() or $.ajax() . Ajax, for example, doesn't matter, for example jQuery('.class') or $('.class') ? With the dollar, it seems to be more convenient, but the article caught my eye where it is indicated that there may be conflicts with the second entry (with $).
- onein fact, no difference, since this is the same thing. And for conflicts there is noconflict - Grundy
2 answers
About conflicts already told. But about the decision - not very. In order to iron out for yourself the $ sign, use the construction
jQuery(document).ready(function($) { // Здесь можно использовать знак $ ничего не опасаясь } The idea is that when you call the ready handler, the first parameter is a jQuery object passed to it, so we take it in $
jQuery.noConflict(); releases the global variable $ and, after calling it, the value of the global variable $ takes the same value that it had before the jQuery library initialization. Accordingly, this function must be called if the $ variable is initialized before the start of jQuery and you want to save this value.
- and
$.noConflict();no need to add, as indicated by the link provided by @Grundy api.jquery.com/jquery.noconflict ? - Iurii Golskyi - one@DidMazay Expanded Response - Anton Shchyrov
Both $ and jQuery are references to the same function, so in the context of one jet it is completely unimportant what to use. But the $ sign is interesting and short, convenient for use in everyday life.
But the problem is that not only jQuery developers understood the strength of the dollar sign and also use it as an interface to access their development ( Prototype , MooTools , Zepto.JS , etc.).
Therefore, if you use several libraries that are also used by $ , take care to avoid conflict (transfer to closure, noConflict in libraries, or use ... commodity variables: jQuery , for example, hardly anyone will take this variable).