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
Jourdan Norman
6,335 PointsWhy is the button class not updating to "selected" in my code?
When I click on a button, the class isn't changed to "selected" and it never stays dark grey once clicked. Is there something wrong with my code?
$(document).ready(function () {
$('button').click(function() {
$("button").removeClass("selected");
$(this).addClass("selected");
});
}); //end ready
1 Answer
Steven Parker
243,656 PointsThis little piece of code looks good.
But there could be an issue in other JavaScript, HTML, or even CSS.
You can share everything at once if you make a snapshot of your workspace and provide the link to it.
Jourdan Norman
6,335 PointsJourdan Norman
6,335 PointsSure. Here's the complete code: https://w.trhou.se/37c0uin6o0
Steven Parker
243,656 PointsSteven Parker
243,656 PointsAre you sure that's the right snapshot?
I could not find your code snippet in the app.js file, and I also did not see any rules for a selected class in the main.css file.
Jourdan Norman
6,335 PointsJourdan Norman
6,335 PointsI'm sorry, that was the subsequent challenge workspace. This one should be correct: https://w.trhou.se/ene724tqy1
Steven Parker
243,656 PointsSteven Parker
243,656 PointsIt looks like you may have an obsolete jQuery reference.
I replaced it with this one and it appears to work:
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>Even this one is a legacy version, you might see if you can use the current one.
Jourdan Norman
6,335 PointsJourdan Norman
6,335 PointsThank you!
Steven Parker
243,656 PointsSteven Parker
243,656 PointsHappy to help. And say, if they told you to use that particular reference in the course, you might want to submit it as a bug using the Support page.
Jourdan Norman
6,335 PointsJourdan Norman
6,335 PointsWill do! Thanks for the tip.