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)?
LVL 1
Howard BashSenior Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Maybe this will help

http://forum.jquery.com/topic/jquery-not-recognized-even-though-jquery-library-referenced

Generally it should work without the below lines but then also try
this
Run this code before any jQuery Code runs and see
var $ = jQuery.noConflict();
0
GaryCommented:
$ 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.
0
leakim971PluritechnicianCommented:
Open this file (this is the version 1.10.2 of the jUQery plugin) :
http://code.jquery.com/jquery-1.10.2.js

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 !
0
Rainer JeschorCommented:
Hi,
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).

HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.