What are the different type of selectors in Jquery
In javascript we can hold or find an object by this below ways
document.getElementById("id"),
document.getElementsByName("name").
Like that in jquery we can hold or get an element from these below different ways. Mainly we can hold or get an element in jquery by using css holding of an element. here i am giving some examples
In Jquery we can select a element in different ways. Here the type of selectors with examples..
By
1.Element Id
by "Id" of the element we can get the value of it .see the example
<div id="hello">Hello Dotnetspiders</div>
<script type="text/javascript">
//Select the element by it's ID
alert($("#hello").text()); // Hello Dotnetspiders
</script>
2. Element by Class
by "Class" of the element we can get the value of it .see the example
<div calss="hello">Hello Dotnetspiders</div>
<script type="text/javascript">
//Select the element by it's class
alert($(".hello").text()); // Hello Dotnetspiders
</script>
3.By Attribute
<input type="text" name="name" value="Dotnetspiders" />
<input type="text" name="Age" value="10" />
<script type="text/javascript">
//Select the element by it's attribute
alert($("input[name=name]").val()); //Dotnetspider
alert($("input[name=Age]").val()); //10
</script>
4.By Hierarchy CSS
Simpler to how we apply css to elements in the same way we can use the hierarchy to get the elements
In the following code we are going to apply background color to tr..
<table>
<tr><td>Dotnetspider</td></tr>
<tr><td>Dotnetspider</td></tr>
<tr><td>Dotnetspider</td></tr>
</table>
<script type="text/javascript">
$("table tr").css("background-color","yellow");
</script>