Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML jQuery Basics (2014) Introduction to jQuery Ways to Include jQuery in a Project

JQuery function not running

I have been racking my brain to figure out why my JQuery isn't running. The browser tools say that $(document) is undefined. It doesn't appear that .ready(myCode) is being loaded at all. As far as I can tell, I have copied the code exactly as it appears in the lesson.

<!DOCTYPE html>
<html>
<head>
<title>Take Evasive Action</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<p class="warning">
<span>It's A Trap!</span>
</p>
<div class="image">
<img src="img/ackbar.gif" />
</div>
var myCode = function() {
$(".warning").hide().show("slow");
}
$(document).ready(myCode);

3 Answers

Problem solved. Anyone else having issues with this project, or just curious, should visit this forum post and watch Andrew's video:

https://teamtreehouse.com/forum/jquery

Turns out there are technical issues with the "//" method of linking to JQuery. Very important info to know.

Tricia Martin
Tricia Martin
19,604 Points

Did you add the jQuery script file to the HTML page?

<!DOCTYPE html>
<html>
<head>
    <title>Take Evasive Action</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
  <p class="warning">
    <span>It's A Trap!</span>
  </p>
  <div class="image">
    <img src="img/ackbar.gif" />
  </div>
  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

Yeah. Sorry, I just couldn't get it to render correctly to the forum.

Tricia Martin
Tricia Martin
19,604 Points

Click the link below labeled 'Markdown Cheatsheet' for tips on getting your code to render. Basically you just put three tick marks ( ` ) with no spaces before the first line of code and after the last line of code.

Thanks. Got it. I was using apostrophes.