0

Newbie so please don't beat me up.

I'm trying to run a simple javascript function using the jquery library. I've tested it on jsbin and it runs. However when I go to my SharePoint 2013 page, insert a Script editor web part and insert the code. It keeps hanging up at $ not defined. So that tells me it's not loading the jquery library even though I have referenced it: ">. FYI: I also tried using the absolute url as well and no difference.

I've been reading in at least two places that I can add a reference to the jquery library in the script editor web part. I know I should be adding it to a Master Page ideally but for now can someone please verify whether or not you can reference your jquery library in a script editor webpart. Thanks in advance.

  • Is there any other js files (used jQuery in those files) applied on the same page? – Sohail Shaikh Dec 27 '18 at 6:21
0

Add the following JavaScript into script editor web part to check if it works.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    alert("Test");
});
</script>

If you can't access the external web in the server, we can download the jQuery library and upload the js file into Site Assets library, then using the code below to test.

<script src="http://sp2013/SiteAssets/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    alert("Test");
});
</script>
0

Troubleshooting

  1. Open your page and go to the browsers developer tools.
  2. Check if your jQuery file is loaded or not.

Possible solutions

  1. Add jquery file in Site assets library in your site and refer it in your code(You can can also use CDN. But keeping jquery file in your site is best way in my point of view).

  2. If you are loading jQuery file multiple times on your page then there maybe the error because of jquery conflict. To avoid that use code given in my answer: jQuery and jQuery multi file upload scripts are not loading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.