-4

I was copying the code from this website http://codepen.io/githiro/pen/ICfFE to use for my website and i've got an error. The very first function starts with $, $(function(){ however when I put this through and open it up on google it gets an error saying $ is undefined. I should also point out that I have called the jquery.

<head>
    <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
    <script src="script.js"></script>
    <script src="jquery-2.2.2.js"></script>
    <title> What Instrument are you? </title>
</head>

How would I fix this? Thanks for your help!

  • look into the settings/javascript section, you should see all the dependencies required for running this example. – Alexus May 10 '16 at 12:56
  • 1
    Note that your `script.js` (which I assume is where your code lives) is included *before* jQuery. You'll want to reverse that. – Paul Roub May 10 '16 at 13:44

2 Answers2

0

You need to add jQuery to your page before your main script body.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
k10der
  • 628
  • 1
  • 11
  • 14
0

open it up on google it gets an error saying $ is undefined

This generally means that your jQuery reference is missing. Ensure that you include it prior to the <script> tag that contains your jQuery code :

<!-- Example CDN Reference to jQuery -->
<script src="https://code.jquery.com/jquery.min.js"></script>
<script>
    $(function(){
         // Your code here
    });
</script>
Rion Williams
  • 69,631
  • 35
  • 180
  • 307
  • What Instrument are you? That's what I have. The javascript is running out of the html – user3500310 May 10 '16 at 12:58
  • Make sure that you include your jQuery reference **prior** to your `script.js` file if it contains any jQuery code (i.e. `$(function{ ... });`). You'll want to also ensure that your reference is correct and doesn't throw any errors within the Console (i.e. indicating that it was loaded correctly). – Rion Williams May 10 '16 at 12:59
  • Oh. I see thanks!! – user3500310 May 10 '16 at 13:01