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

Why does this code doesn't work?

<html> <head> </head> <body> <ul> <li id="first">Thing 1</li> <li id="second">Thing 2</li> <li id="third">Thing 3</li> </ul> <script src="http://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script> <script src="app.js"></script> </body> </html> //JavaScript file $("li").find("#first").css("color","red");

1 Answer

Hi Vic,

First of all, great that you post a code example :). However it might be better to format the code in a way it's better structure and readable (check out the markdown cheatsheet).

To answer your question.
Did you define the doctype at the beginning of your HTML? Not sure if this can cause a problem. But it's best practice to do so.

<!DOCTYPE html>

Did you put your app.js inside a folder or is it in the root folder?

The code of your javascript file could be simpler:

 $("#first").css("color","red");

Also it might be a good idea to wrap your code into a document.ready() function, so that your code is run when the complete page is loaded.

$( document ).ready(function() {
    $("#first").css("color","red");
});

Let me know if this works for you!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Bram! I took the liberty of changing your comment to an answer. This helps keep the forums tidy by marking the answer as "answered", but also allows for voting on your answer! :sparkles:

Jennifer Nordell Thank you!