Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do dot and hash symbols mean in JQuery?

Tags:

jquery

I feel confused of the dot and hash symbols in the following example:

<DIV ID="row"> <DIV ID="c1">               <Input type="radio" name="testing" id="testing" VALUE="1">testing1 </DIV> </DIV>  

Code 1:

 $('#row DIV').mouseover(function(){          $('#row DIV').addClass('testing');       }); 

Code 2

  $('.row div').mouseover(function(){         $(this).addClass('testing');     });​ 

Codes 1 and 2 look very similar, and so it makes me so confused that
when I should use ".row div" to refer to a specific DIV instead of using "#row div" ?

like image 907
user327712 Avatar asked May 18 '10 19:05

user327712


People also ask

What is use of dot 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 the $() 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. A (selector) to "query (or find)" HTML elements.

What is '#' in JavaScript?

2021 update: Class fields are public by default, but private class members can be created by using a hash # prefix. The privacy encapsulation of these class features is enforced by JavaScript itself.

What is the jQuery short symbol?

The $ sign is nothing but an identifier of jQuery() function. Instead of writing jQuery we simply write $ which is the same as jQuery() function. A $ with a selector specifies that it is a jQuery selector.


1 Answers

The hash (#) specifies to select elements by their ID's

The dot (.) specifies to select elements by their classname

You can read more about the selectors here: http://api.jquery.com/category/selectors/basic-css-selectors/

like image 110
Jeff Schumacher Avatar answered Sep 21 '22 13:09

Jeff Schumacher