I was recently listening to a podcast which made a comment on using $() vs using jQuery(). It was stated that every time $() was used a new object would be created and when jQuery() was used this was not the case. I google’d around but couldn’t find anything on this specific topic.
I realize this is not a typical example, but the following is the reason I am interested in the answer to this question.
I have a page that the user will keep loaded in a browser for a whole day (24 hours, or possibly longer) and updates are done to the DOM every ~5 seconds as the result of an AJAX call via jQuery (the AJAX call portion is irrelevant to updating the DOM – the update to the DOM is done using a string of HTML and a call on a jQuery object to .empty() and then .html()).
Since hearing this, I subsequently switched all of the $() calls to jQuery() calls, but I would like to know:
Is using $() vs using jQuery() a bad practice? Is there a negligible difference between the two? Or is it actually noticeable on larger projects?
No, it’s not bad practice, and there is no performance difference.
The
$andjQueryidentifiers refer to the same function instance.This is done by the last line of jQuery.js: