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! While you're at it, check out some resources Treehouse students have shared here.
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
Sebastian Andersson
7,468 PointsWhy doesn't my jQuery work?
I can't get my code to work. It just won't respond even though I did it exactly as in the jQuery basics lesson.
My HTML code:
<!DOCTYPE html>
<html>
<head>
<title>Spoiler</title>
<link rel="stylesheet" href="css/style.css">
<link rel ="stylesheet" href="css/normalize.css">
<meta charset="UTF-8">
</head>
<body>
<p class="warning">
<span>It's a trap!</span>
</p>
<script src="scripts/app.js" type="text/javascript" charset="UTF-8"></script>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
</body>
</html>
My JavaScript code:
$(".warning").hide().show("slow");
4 Answers
Chyno Deluxe
16,936 PointsOk try this then and see if it works. sometime when working locally and seeking external files without http: gives errors or won't fetch the files.
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="scripts/app.js" type="text/javascript" charset="UTF-8"></script>
Chris Shearon
Courses Plus Student 17,330 PointsYou're loading the jquery script after your local script. Put the jquery script before your local one and it'll work. Otherwise you'll get a reference error.
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="scripts/app.js" type="text/javascript" charset="UTF-8"></script>
Chyno Deluxe
16,936 PointsYour script tags are not in correct order. You need to request the jQuery library first than your personal scripts.
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="scripts/app.js" type="text/javascript" charset="UTF-8"></script>
Since your app.js depends on jquery to work you must send the request for it first. Hope this helps
Sebastian Andersson
7,468 PointsIt still doesn't work. When I go into the Page Source on the website I get a message saying "This webpage is not found ERR_FILE_NOT_FOUND"
Is there something that I have to do in order for the script to communicate with the .html?
Chyno Deluxe
16,936 PointsAre you working on a local editor or are you working on Treehouse's workspaces? If you are working on the workspaces can you post the link to that workspace so i can review it?
Sebastian Andersson
7,468 PointsIt's sublime text 3. I have tried it on workspaces and it works.
Sebastian Andersson
7,468 PointsSebastian Andersson
7,468 PointsThat's awesome, man. Thank you for taking up your time. Much appreciated.
WITH LOVE
Sebastian Andersson
7,468 PointsSebastian Andersson
7,468 PointsThat's awesome, man. Thank you for taking up your time. Much appreciated.
WITH LOVE
Chyno Deluxe
16,936 PointsChyno Deluxe
16,936 PointsAwesome! Glad I could help.