jQuery Selectors


jQuery Selectors are used to select the element. jQuery selectors play an important role in jQuery library.


JQuery Selectors

jQuery Seletors are based on such as : Name, Id, Classes and many more…

The very basic selector(Name) example :

jQuery Selctors Example :

<!DOCTYPE html>
<html>
<head>
<title>jQuery Selectors Example</title>
 <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js">
 </script>
<script type="text/javascript">
         $(document).ready(function(){
          $("div").css("background","yellow");
          });
</script> 
  
</head>	
<body>
<div> 
This id test div one .....and background is added using jquery...
</div>
<br>
<div> 
This id test div two.....and background is added using jquery...
</div>

</body>
</html>                              

Try it »

Main jQuery Selectors

[table width=”100%” colwidth=”20|100|50″ colalign=”left|left|center|left|right”]
No,Selector
1, Name : The example of name tag are

<p> <div>

2, Class :The example of class selector is –

<div class="test"></div>

Here class selector is “test”.
3, ID : The example of ID selector is –

<div id="MainDiv"></div>

Here class selector is “MainDiv”
[/table]

More jQuery Selectors

[table width=”100%” colwidth=”20|100|50″ colalign=”left|left|center|left|right”]
No,Selector,Example
1, $(“*”) : Selects all elements in the page. , See Detail & Demo »
2, $(this) :Selects current element.,See Detail & Demo »
3, $(“p.myclass”) : Selects all <p> which have class “myclass”.,See Detail & Demo »
4, $(“ol li:first”) : Selects first <li> element of the <ol>,See Detail & Demo »
5, $(“ol li:last”) : Selects last <li> element of the <ol>,See Detail & Demo »
6, $(“[href]”) : Selects all elements with “href” attributes.,See Detail & Demo »
7, $(“tr : even”) : Selects all even tr elements of the table.,See Detail & Demo »
8, $(“tr : odd”) : Selects all odd tr elements of the table.,See Detail & Demo »
[/table]


Advertisements

Add Comment

📖 Read More