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

I have a question about if my jquery code is okay. (codepen included)

I made a simple FAQ that fades in and out when you click the button. My code is as follows.

$(document).ready(function(){
    $("#main-div").hide(); // if user has javascript enabled they can still see the text
    $("#instructions").click(function() {
        $("#main-div").fadeToggle(1500);
    }); // end click
}); // end ready

My first question is I hide the main-div on line 2. The reason I used the hide function, is because some may not have javascript enabled on their browsers, and I want those people to still see the text/faq. Next on line 3 of my code, I added a click function to the button with the id of instructions. On line I added the fadeToggle function, which fades in and out the text. My question is, is my code okay, would this be acceptable? Also is it okay that I added the #main-div twice to my programming, is this repeating my programming?

Thank you for any advice codepen http://codepen.io/mike316/pen/oLVmwR

1 Answer

Steven Parker
Steven Parker
242,284 Points

Your code looks fine. :+1:

You are not repeating yourself when you use #main-div because it is for different things and at different times.

My only suggestion is that your comment should probably say: "if user has javascript disabled..." (instead of enabled)

LOL. You're right, I'll fix that. Thanks again for your help Steven, I really appreciate it.