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 Introduction to jQuery DOM Manipulation Showing and Hiding Content

Is there a way to get the buttons to fade in without having to retype another line of code ?

$('img').css("display", "none").fadeIn(1600);
$('button').css("display", "none").fadeIn(1600);

1 Answer

Steven Parker
Steven Parker
231,269 Points

These lines select different elements.

I'm guessing by "another" you mean "other than the top line"? So the issue is that the first part of the top line selects image (img) elements, not buttons. So while you can chain functions together, they will all only affect the images.

The second line is exactly the same but it selects the buttons. So the trick to doing both on one line would be to select the images and the buttons at the same time.

And yes, you can select more than one element type by separating their tag names with a comma:

$('img,button').css("display", "none").fadeIn(1600);

Remember, just about any selector you can use in CSS will work in jQuery (plus a few extra only jQuery has!).