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
jonasdahms
19,331 Points[solved] jquery basics: teachers code is working, typed the same code isnt working. Whats up?
In this lesson we only modified app.js. My code looks exactly the same as the teachers, except for comments. This his works totally as intended. Mine doesnt.
teachers code; http://puu.sh/i5SnY/37b99bf0cf.jpg
my code:
$(".spoiler span").hide();
$(".spoiler").append("<button>Reveal Spoiler!</button");
$(".button").click(function() {
$(".spoiler span").show();
$(this).remove();
});
everything after the button.click doesnt work, but I dont see any differences from my code to the teachers code. Am I overlooking something or what is up?
jonasdahms
19,331 PointsNevermind I fixed I myself by rewriting the javascript code. Though I still wonder, what was wrong in the first try. But its working now so doesnt really matter. Thanks for helping out, atleast I know now how to snapshot my workspace if I ever have to ask here again.
Marcus Parsons
15,719 PointsThat's awesome! It's incredibly weird that you had to physically rewrite the code though. Oh well. We may never know =D Happy Coding, Jonas!
3 Answers
Marcus Parsons
15,719 PointsI see the problem with the markup now that Daniel added some syntax highlighting to it. You must have accidentally put a dot before button to make it a class selector. It should be just a "button" selector, not ".button". Easy mistake to make and not catch haha
$(".spoiler span").hide();
$(".spoiler").append("Reveal Spoiler!);
$("button").click(function() {
$(".spoiler span").show();
$(this).remove();
});
Daniel Newman
Courses Plus Student 10,715 PointsUse code-beautifier and Markdown Cheatsheet just below comment box to provide firm code. Look on your sample:
$(".spoiler span").hide();
$(".spoiler").append("Reveal Spoiler!);
$(".button ").click(function() {
$(".spoiler span ").show();
$(this).remove();
});
Are you sure that ("Reveal Spoiler!); and $(".button ") and $(".spoiler span ") have no problem like missing <">, and have no extra whitespaces in selectors?
jonasdahms
19,331 PointsAhh yes I see there was a dot where it shouldnt have been, thanks for pointing that out. Of course it doesnt work then. Those misstakes with . and , are so easy to overlook hahaha
Marcus Parsons
15,719 PointsAnd there was a missing double quotation mark after Spoiler! lol :D Oh well, at least you got it working now :) Happy Coding!
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsHi Jonas,
Can you post a snapshot of your workspace? There's no reason (JavaScript wise) that that screenshot shouldn't work. If you don't know how to do that, here's how: http://www.teamtreehouse.com/forum/workspace-snapshots