Here's a list of selectors I've seen before:
$('.menu')
$('menu')
$('#menu')
Could anyone clarify in what scenario(s) each would be used?
Here's a list of selectors I've seen before:
$('.menu')
$('menu')
$('#menu')
Could anyone clarify in what scenario(s) each would be used?
The jQuery selector syntax is the same as that of css. So ".menu" will select everything with a class of menu, "#menu" will select the object with an id of menu (there should only be one! "menu" will try to select elements of type menu.
An example;
$('.menu'): all element with a class menu
$('menu'): all menu element
$('#menu'): the element with an id of menu
$('.menu')
... select elements withclass='menu'
$('menu')
..... select<menu />
elements$('#menu')
... select an element withid='menu'
1st finds
<div class="menu"></div>
2nd finds
<menu></menu>
3rd finds
<div id="menu"></div>
Note that these rules applies and are based on CSS.
Class Selector (“.class”)
Selects all elements with the given class.
Element Selector (“element”)
Selects all elements with the given tag name.
ID Selector (“#id”)
Selects a single element with the given id attribute.
Reference: http://api.jquery.com/category/selectors/basic-css-selectors/
Taken from http://forum.codecall.net/javascript-tutorials/14363-jquery-selectors.html