Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML jQuery Basics (2014) Introduction to jQuery What is jQuery?

hakan Gülay
hakan Gülay
8,489 Points

ı couldnt use jquery

Hi, ı want to use jQuery on sublime text 3 but it doesnt work! ı really dont know why. for example;

<!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">
</head>
<body>
  <p class="warning">
    <span>It's A Trap!</span>
  </p>

    <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

that is code and

jQuery(".warning").hide();

this is other code. but It's A trap! doesnt disappear on page

5 Answers

hakan Gülay
hakan Gülay
8,489 Points

<!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"> </head> <body> <p class="warning"> <span>It's A Trap!</span> </p>

<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>

</body> </html>

this is my code and other code for query jQuery(".warning").hide();

ı did it now.

ı removed "js/" from src="js/app.js" ı mean that became src="app.js" and it works now.

J Scott Erickson
J Scott Erickson
11,883 Points

Without knowing the structure of your page exactly this is my best suggestion

Note that the Javascript includes are at the bottom of the html:

<!Doctype html>
<html>
  <head>
    <!-- Your Css and Whatever else here -->
  </head>
  <body>
    <div id="warning">
     <!-- This is your stuff and whatever -->
    </div>



    <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
  </body>
</html>

js/app.js

  $(".warning").hide();
  // This Should hide it for ya.
hakan Gülay
hakan Gülay
8,489 Points

god why all code doesnt appear :) nvm ı should remove "js/" just but ı dont know why it works when ı remove it

J Scott Erickson
J Scott Erickson
11,883 Points

Then your issue was that app.js was not in a folder named js

your file structure should have been like so:

index.html

js/ --> app.js

css/ --> something.css

While not required at all, this allow you to compartmentalize your files into coherent structures.

hakan Gülay
hakan Gülay
8,489 Points

ı got it and my last question is why we use this code for jquery

<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>

this code gets information from site ?

Bill Hinostroza
Bill Hinostroza
19,273 Points

With this code you're telling the browser to grab the jQuery library from that source and with that you're able to use jQuery.

hakan Gülay
hakan Gülay
8,489 Points

thank u guys ı understood now :)