Adding jQuery to a SharePoint Page: Step One, Always
No matter how many times I add jQuery to a page in SharePoint, this is absolutely *always* the first thing that I do:
<script language="javascript" type="text/javascript" src="/Scripts/jquery-1.5.min.js"></script> <script language="javascript" type="text/javascript" src="/Scripts/jquery.SPServices-0.6.1.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function() { alert("jQuery"); }); </script>
If that alert in line 7 which is wrapped in a
$(document).ready
fires, then my script references are good. I can’t tell you how many times I’ve talked people through that simple step. It even hangs me up, so it’s always good to do that alert first. (Sure, the alert can say “Bob’s your Uncle” or “Strawberry Jam”, but alert *something*.)
Hi Marc,
This is the second time your posts save my day! Can’t thank you enough.
Pari
Hi Marc,I watched your share point videos its really great helpful.
Could you please give step by step process how to use jquery in SharePoint.
Saran:
That’s a very wide topic!
M.
Marc,
I know that this is an old posting, but this has helped me tremendously. I am just starting to get into learning jQuery, and with this article, I have FINALLY gotten my references right, and I know that the scripts are firing up correctly.
Thank you,
Ken
I’m new to client side coding with SharePoint 2013 and I see people not only using JavaScript but also JQuery. I know this article is for SharePoint 2010, but is the method of referencing JQuery libraries the same for SharePoint 2013. Someone I know, said that there is already a reference to JQuery in SharePoint 2013, and therefore I don’t need these references. What is currently, in 2016, the best method to connect to JQuery in SharePoint 2013? and does the story change for SharePoint 2016?
@Jane:
Adding jQuery to a page is the same regardless what version of SharePoint you use, and even if you aren’t using SharePoint at all but just a Web page. While Microsoft has said it “supports” jQuery (whatever that means), it is not loaded in the product at all. In fact, Microsoft went to a lot of [unnecessary] trouble to build their own library called mQuery that mimics much of what jQuery does. See: SharePoint JavaScript Context Development Part 6 – jQuery vs SharePoint. jQuery is just a JavaScript file, and we load JavaScript using the same techniques regardless what file it is.
M.