8

Suppose I have the following html:

<div id="test1">hi</div>
<a href="#" onclick="showDiv()">click here</a>

and the javascript:

function showDiv() {
    $("#test1").hide();
}

When I try it on jsfiddle, it returns:

$ is not defined

Did I miss some setting in jsFiddle?

Thanks.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
Kintarō
  • 2,947
  • 10
  • 48
  • 75

6 Answers6

20

That suggests that you have not selected one of the jQuery libraries from the left hand side of the screen.

JSFiddle

James M
  • 18,506
  • 3
  • 48
  • 56
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
10

These answers are old and for anyone looking for an updated version the dropdown menu is now located on the gear next to the word Javascript at the top right of your javascript window in jsfiddle.

Kyle Wilson
  • 126
  • 1
  • 3
4

Screenshot of the current (Dec 2015) version of jsfiddle:

enter image description here

I just wasted a lot of time on this silly error as well - frameworks and extensions are now selected via the "JAVASCRIPT *" button in the JavaScript pane!

Drew
  • 24,851
  • 10
  • 43
  • 78
1

If anyone is reading this in 2017, then make sure to add the jQuery link using https protocol. This is to be added in the External resources tab present at the left of the page.

Harshil
  • 436
  • 1
  • 7
  • 16
0

Either do what @Drew and @James show.

if you remain having problems (which I know I did the other day), you can add an external resource from a CDN library

"http://code.jquery.com/jquery-1.9.1.min.js"

good luck !

Daniel
  • 4,816
  • 3
  • 27
  • 31
-1

$("#test1").hide();

the above is not defined meaning the $

Example.

jQuery(document).ready(function($) { $("#test1").hide(); } `

jQuery(document).ready(function(IsNowDefined) // just for explanation IsNowDefined("#test1").hide();

Grmn
  • 542
  • 2
  • 9