tags:

views:

69

answers:

4

I often see these 2 selectors, what is the difference? Thanks

+9  A: 

This is a ID selector (1)

$("#el")

This is a class selector (2)

$(".el")

So

<div id="el"></div> <-- (1) matches this -->
<div class="el"></div> <-- (2) matches this -->

References

BrunoLM
+4  A: 

# matches an element with that ID. . matches elements with that class.

See more: http://api.jquery.com/category/selectors/

Ian Henry
+1  A: 

The # version is seeking by tag ID while the . version searches by CSS class.

Andrew Barber
+2  A: 

$("#id") selects element by its id, while $(".class") selects elements by the specified class.

Satoru.Logic