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
Mustafa Uslu
996 PointsMy javascript.js file wont work. The animation doesent go through.
Here is the code: <!DOCTYPE html> <html>
<head> <title>Blog Preview Example</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body> <div id="flashMessage"> Your changes have been saved! </div> <div class="blogNewPost"> <h1 class="blogPage-title">New Blog Post</h1> <p class="blogTitle-area"> <label>Title</label> <input type="text" id="blogTitleInput"> </p> <p class="blogContent-area"> <label>Content</label> <textarea id="blogContentInput"></textarea> </p> <p> <button id="previewButton">Preview</button> </p> </div> <div class="blogPreviewArea"> <h2 id="blogTitlePreview"></h2> <div id="blogContentPreview"> </div> </div>
<script language="JavaScript" type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>
<script src="myjs.js"></script>
</body>
</html>
<!-- Extern js file-->
$(document).ready(function () { // // $('flashMessage').hide(); // $('flashMessage').fadeIn(1000); // $('flashMessage').slideUp();
});
3 Answers
I Dilate
3,983 PointsEverything in your external .js file's function is commented out using // ?
Mustafa Uslu
996 PointsYes. It was to find the error.
I Dilate
3,983 PointsOkay, but when you comment out a line of JavaScript - that line isn't going to do anything. Currently, there are no animations running in your script because they're all commented out.
Also, you have a syntax problem...
You're trying to use jQuery to select an element with an ID attribute of "flashMessage".
You've used this:
$('flashMessage')
However, the CSS selector for an ID is the pound/hash symbol #, so you need to use it in your selector.
For example:
$('#flashMessage').hide()
If you were trying to select an element using its class attribute, you'd use a dot instead, like this:
$('.flashMessage').hide()
Your jQuery selectors need to be specific about the type of attribute you're asking it to search for - it won't guess.
Are you using the JavaScript Console in your browser for debugging? If not, you should consider turning it on, because the error messages that it shows for syntax problems like this will help you fix simple mistakes quickly. It's an essential tool to learn to use as you progress. Google to see how you can turn it on for the specific browser you're running.