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

What is the function of the '.' when calling the 'warning' class? (e.g. $('.warning'))

The ending snippet is as follows:

$('.warning').hide().show('slow');

What is the function of the period ('.') before warning? Is this a search function of sorts?

3 Answers

Hello Steven,

In this jQuery code, the '.' before warning is like saying you are selecting an element by it's class. Since classes are associated with '.' and id's with '#', this is how you select elements in jQuery.

class = $('.warning').hide().show('slow');

id = $('#warning').hide().show('slow');

hope this helps.

Julian Gutierrez
Julian Gutierrez
19,325 Points

In JQuery one can target an element by using selectors similar to css. Here the '.' means that you are targeting an element with the class of warning. If you were needing to target an element with the id of warning you would use

$("#warning")

The dot tells jQuery to select any element with a class of "warning" and then do something with it. It's the same way you'd write a warning class selector in a CSS file. Many jQuery selectors mirror the format used in CSS.