jQuery vs. $

I have some SharePoint pages with a fair amount of jQuery code.  I am finding that for some sections I must used the word "jQuery" for jQuery functions whereas in other places I can use the word "$" for jQuery functions.

Why is this the case and further how and when does my page recognize "$" for "jQuery" (which may be the same question phrased differently)?
Howard BashSenior Software EngineerAsked:
Who is Participating?
Rainer JeschorConnect With a Mentor Commented:
this is due to the fact that SharePoint itself (starting with SharePoint 2010) uses the namespace/alias $() for certain areas (FAST Search center page and some other) - therefore it could work or not.
Explicitly using  "jQuery" instead of "$" should work (at least it does on my last 4 years projects).

Randy DownsConnect With a Mentor OWNERCommented:
Maybe this will help


Generally it should work without the below lines but then also try
Run this code before any jQuery Code runs and see
var $ = jQuery.noConflict();
GaryConnect With a Mentor Commented:
$ is the default for jQuery and other js frameworks.
If you are not using any other frameworks then it should be safe to use, but if you are then one of the frameworks need to be assigned its own operator.
leakim971Connect With a Mentor PluritechnicianCommented:
Open this file (this is the version 1.10.2 of the jUQery plugin) :

locate ths following : window.$ = jQuery;

it make the global var << $ >>  a SHORTCUT of jQuery.

But sometime, you may have some other Javascript framework using the SAME shortcut.
For example Mootools. In this case you CAN't use << $ >> anymore as shortcut of jQuery.

You can use an new shortcut using  jQuery.noConflict() : http://api.jquery.com/jQuery.noConflict/

For example : window.j = jQuery.noConflict();

after this line you can use << j >> instead << $ >> and << $ >> can be "resassigned" by an other framework.
Be sure to run this BEFORE the other framework !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.