JQuery selectors allow you to select and manipulate HTML elements. JQuery selectors find HTML elements based on id, name, attribute, classes etc.
General syntax for JQuery selector is $()
Ex:
Element selector
$(“p”) – select all p element on that page.
ID selector
$(“#txtUserName”) – select control with mention id.
Class selector
$(“.myclass”) – select control, html element which is having mention class.
Attribute Selector
$(“a[target=’_blank’]”) – select anchor tag which is having mention attribute.
$(*) – select all elements available in DOM.
Parent/Child Selectors
JQuery allows you to select HTML elements based on parent child relations.
<div id=”mainarea”>
<p>This is my content</p>
</div>
<script type=”text/javascript”>
$(“#mainarea > p”).css(“font-weight”, “bold”).css(“color”, “red”);
</script>
Note: -In above script, mainarea is the id of parent div tag and p is the child for this tag.