jQuery Functions and Selectors
Selecting by Class

We don't have to limit ourselves to selecting HTML elements like <p> and <div>; essentially, we can put any CSS selector in quotes and pass it into $(). This means we can select classes, too!

Recall that we can select classes in CSS by using a dot (.). If we have class="red" in our HTML, we can target it in CSS with .red. In jQuery, all we need to do is put '.red' in quotes, and we can pass it to $() to make a jQuery object.


Let's get some practice with the .click() action.

Finish the jQuery code so that it will make all four divs of class '.vanish' fadeOut() 'slow'ly when the button is .click()ed.

Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

On line 2, you'll want to put the button element inside $() to make it a jQuery object.

On line 3, you'll want to select '.vanish' and tell it to .fadeOut() with the input 'slow'. Remember, by making '.vanish' the jQuery object, all .vanishs are affected. We'll learn how to affect just one element soon!

View Preview