SIGN UP MEMBER LOGIN:    
ARTICLE

JQuery Using Selectors

Posted by Alten Chingumbra Articles | JQuery December 22, 2011
In this article we will learn how to use Jquery selectors available for accessing DOM.
Reader Level:

JQuery using selectors

In this article we will look how to use Jquery selectors available for accessing DOM.

So let's get started.

I create an HTML file and add
downloaded jquery-1.4.2.min.js file to below html file named as JQuerySelectors.html. 

JQuerySelectors.html

 
<html>
 <
head>
 <
title>JQuery Sample HTML Page</title>
 
<script src="jquery-1.4.2.min.js" type="text/javascript">
 
</script>
 <
script language="javascript" type="text/javascript">
 
$(document).ready(function() {
 $('#div1').hide();
 });
 
</script>
 </
head>
 <
body>
 <
div>
 <
div id="div1">This is a Section.</div>
 
<div>This is next Section.</div>
 
<div>This is Last Section.</div>
 
</div>
 </
body>
 
</html>


Here is a list of selectors, their syntax and brief description.

JQUERY450.jpg
 

We can select elements based on attributes using below syntax:

$('div [attr-name^=test]') - Selects all div tags with attribute value equal to test.

Now, we will look into custom selectors provided by JQuery. Custom selectors starts with :. Few of them are :even, :odd, :eq etc. We can use :even, :odd for styling alternate rows in a table using below syntax:

$('tr:odd').addClass('alternate');// Adds CSS class
Or
$('tr:nth-child(even)').addClass('alternate');

We can use custom selectors with form's elements like checkbox, textbox etc as shown below:

$(':button:disabled') - Select all disabled buttons

JQUERy470.jpg

JQuery460.jpg

Summary

In this article you have seen
how to using Jquery selectors available for accessing DOM.

I hope this article was helpful!

Resources

Here are some useful related resources:


Login to add your contents and source code to this article
share this article :
post comment
 

Thanks

Posted by Alten Chingumbra Dec 26, 2011

Good One Alten...Thanks for Sharing!!!

Posted by Vijay Prativadi Dec 24, 2011

Nice article, Mr. Alten.

Posted by Alok Pandey Dec 24, 2011

Thanks Mr. Chingumbra.

Posted by Nitin Singh Dec 23, 2011

Hey Mr.Chingumbra you have provided the good insight of the topic...Thanks

Posted by Alec Stewart Dec 23, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor