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 trialHenrik Christensen
Python Web Development Techdegree Student 38,322 PointsWhy does my code not work?
Hello,
I've written the same code as the teacher but when I preview it nothing happens, but it works perfect when the teacher preview the same piece of code.
//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes appropriately
var color = $(".selected").css("background-color");
//When clicking on control list items
$(".controls li").click(function() {
//Deselect sibling elements
$(this).siblings().removeClass("selected");
//Select clicked element
$(this).addClass("selected");
//Cache current color
color = $(this).css("background-color")
});
4 Answers
Markus Ylisiurunen
15,034 PointsHi!
It seems to be almost right. You've forgotten a semicolon from the last line inside the function. Other than that it looks like it's fine.
Hope it helps.
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsThank you Markus, but it made no difference and it's getting a bit frustrating now :-P
Markus Ylisiurunen
15,034 PointsOkay then, seems weird. Can you put all your code (HTML and JS) to CodePen for me to see. My Treehouse account is currently paused so I can't see the video.
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsIt works perfect in codepen but not when I preview here in treehouse o.O
Markus Ylisiurunen
15,034 PointsClassic :) Well one thing that might be wrong is that workspaces use https and you're trying to load jQuery over http. Your browser might block you from doing that. You could try changing http to https for the jQuery script tag.
If that doesn't work try checking your console (F12 in Chrome) if it shows you any errors. And if it doesn't show you any errors try typing $
in the console and see what it says.
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsI don't know what happend - I changed it to https and then back to http and now it's working perfect (same code as before)..
Thank you very fun for all your input and help :-D
Markus Ylisiurunen
15,034 PointsGlad you got it working. Sometimes those kinds of errors are the real pain.
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsHappy I spotted the missing semi colon too in the last line before I went to the comments. I am teaching myself to read code and spot such things. Great you got it working too Henrik! Cheers!