jQuery Tutorial Tutorials - jQuery Selectors

jQuery Selectors

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).

jQuery selector syntax

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

jQuery selector notice

  1. the selector is not case-sensitive. But making sure they are same as element's tag is a good habit.
<div id="myDiv"></div>
<script>
    $("#myDiv"); // recommended
    $("#mydiv"); // it works ,but not recommended
</script>
  1. single quote and double quote are the same .but single quote is recommended.
$("#ID")
// same as
$('#ID') // single quote,is recommended
Date:2019-06-09 01:14:25 From:www.Lautturi.com author:Lautturi