Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hash sign in jQuery calls

Being a pragmatic coder I tend to miss some obvious things and I wonder, What's the difference between

$('loc')
$('#loc')

The more info the better about the ins and outs of #

like image 353
Mantar Avatar asked Dec 06 '10 16:12

Mantar


People also ask

What is hash symbol in jQuery?

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

What does $() mean in jQuery?

In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery.

What does hash character (#) symbol means in CSS?

These are CSS selectors. The hash symbol # means that the element is an ID. So #row would match <div id="row"> . Alternatively, the dot symbol . means the element is a CSS class.


1 Answers

$('loc') is an element selector, looking for <loc> elements.

$('#loc') is an #id selector, looking for id="loc" elements.

Think CSS when looking at almost all jQuery selectors, they're very close if not identical in most cases.

like image 72
Nick Craver Avatar answered Oct 06 '22 00:10

Nick Craver