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

JavaScript

'$' was used before it was defined. $("p").hide();

if i use <script> $("p").hide(); </script> its ok but if i try external file i am getting '$' was used before it was defined. error i put my jquery inside the header and my js file and of the body tag i googled it but cound find answer help please ..

2 Answers

I think what you're doing is including your scripts before the page has had a chance to load. The easiest solution is the include your jQuery and external JavaScript at the bottom of the page, as to make sure everything loads before you try to use it. The other option is to stop the code from running before the page is completely loaded, which can be done like this:

$(document).ready(function(){
    //code you want to execute
});

thank you for you reply i tried using the code inside also but it doesnt work the issue my Js doesnt recognize jquery $ it says jslint problems

Are you linking to your external script before your jQuery? Because that could be the problem. Make sure you link to the jQuery before your script.