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

CSS jQuery Basics (2014) Creating a Spoiler Revealer Using click()

stage 2 code challenge problem this is what i entered: $("button").click("function"(){}); to place an empty

$("button").click("function"(){}); it was asking how to add to the click an empty function to use again in the future. where am I going wrong? i tried it without the paranthesis , with them, pick it..any combo except for the right one. any help would be much appreciated.

//Prevent spoilerphobes from seeing spoilers
//Solution: Hide spoilers and reveal them through user interaction

//1, Hide spoiler
$(".spoiler span").hide();
//2, Add a button
$(".spoiler").append("<button>Reveal Spoiler!</button>");
//3, When button pressed

  //3.1, Show spoiler
  //3.2, Get rid of button
<!DOCTYPE html>
    <title>Star Wars Spoilers</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
    <img src="img/deathstar.png" />
    <p class="spoiler">
        <span>Darth Vader is Luke Skywalker's Father! Noooooooooooo!</span>
    <script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/app.js" type="text/javascript" charset="utf-8"></script>

2 Answers

Alexander Costa
Alexander Costa
11,464 Points

Hello Erika!

The answer should be $("button").click( function (){});

I just did it and it worked.

Don't put parenthesis around anything that is not a string.

I know your question said you tried it without the parenthesis but I just did it and it worked.

d'oh...i'm such a noob! a dollar sign helps in all things....my life and so it would seem jquery! thanks for you help Alexander!