最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - $ is not defined in jsfiddle - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Mar 18, 2013 at 1:29 Drew Noakes 311k169 gold badges697 silver badges763 bronze badges asked Mar 18, 2013 at 1:15 KintarōKintarō 3,17712 gold badges54 silver badges81 bronze badges 9
  • 4 Make sure you add jQuery reference... – sgeddes Commented Mar 18, 2013 at 1:16
  • 2 Did you select Jquery API from left nav bar? – Hanky Panky Commented Mar 18, 2013 at 1:16
  • 1 Could you share the link to the fiddle? – Srikanth Venugopalan Commented Mar 18, 2013 at 1:17
  • 2 Why are people downvoting this question, and voting for it to be closed? It's a perfectly good question, and may serve to help someone else who experiences exactly the same issue. Thank you for your question, @Kintaro. – Drew Noakes Commented Mar 18, 2013 at 1:23
  • 3 @thesystem, don't assume what's obvious to you is obvious to others. – Drew Noakes Commented Mar 18, 2013 at 1:25
 |  Show 4 more comments

6 Answers 6

Reset to default 20

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

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.

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

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!

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.

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 !

$("#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();

发布评论

评论列表(0)

  1. 暂无评论