Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between $('#___') and $('.___') in JQuery

Tags:

jquery

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

like image 640
user470310 Avatar asked Dec 05 '22 01:12

user470310


2 Answers

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

  • All Selectors
  • ID Selector
  • Class Selector
like image 102
BrunoLM Avatar answered Dec 07 '22 15:12

BrunoLM


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

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

like image 31
Ian Henry Avatar answered Dec 07 '22 15:12

Ian Henry