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

HTML jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 1

Why there is a # character in "$("#imageGallery a").click(function(event)"?

Why there is # in the beginning of imageGallery and not . ?

Sauli.

2 Answers

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

You'll have to post the code you're talking about, but the '#' is used to reference an ID. Here is an example:

<div class="this_is_a_class" id="this_is_an_ID"></div>
.this_is_a_class {    // We use classes to style our markup
    background-color: tomato;
}
$("#this_is_an_ID").click(function(event){   // We use IDs to grab elements using javascript
    alert("The div was clicked");
});

So, '#' denotes an ID, while '.' denotes a class. Best practice recommends IDs only for use with javascript and not for styling. It is ok to use classes in both contexts. Did this help?

Thanks, this did answer the question I had.