In this chapter,we will learn about the jQuery selectors,which is the most import part in jQuery. All manipulations,effects and events are acted on selected elements.
Selectors are used to find out the matching elements from DOM(Document Object Model).
All selectors use the $() factory function to select elements. $()
is a synonym of jQuery()
function.
$('selector-criteria') // same as jQuery('selector-criteria')
Following is a simple example.when the user clicks on button, the color of all the elements with a tag name div
would be changed.
Try now
<div id="myDiv"></div> <script> $("#myDiv"); // recommended $("#mydiv"); // it works ,but not recommended </script>
$("#ID") // same as $('#ID') // single quote,is recommended