phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


jQuery - Selector: XPath Selectors

Tag: jQuery, $(), factory, function, selectors, XPath   Category: JavaScript
post: 21 Mar 2008 read: 871


jQuery Selector Step By Step Tutorial - Part 4: XML Path Language (XPath) is a type of language for identifying different elements of their values within XML documents. To see how jQuery works with XPath, look following sample.

In html document, we have 3 link like this:


<a href="love.html">Love me do</a>
<a href="obladi.pdf">Obladi Oblada</a>
<a href="mailto:music.rock">Rock 'n Roll The Music</a>

We want to give unique style every links. So, add the styles at css, such as:


a{
 color:#FF6600;
}
a.mailto{
 color:#00CC00;
}
a.pdf{
 color:#FF0000;
}
a.love{
 color:#FF00FF;
}

Then, modify your js like following:


// JavaScript Document
$(document).ready(function(){
  $('#favorite > li').addClass('category');
  $('#favorite li:not(.category)').addClass('songs');
  
  $('a[@href^="mailto:"]').addClass('mailto');
  $('a[@href$=".pdf"]').addClass('pdf');  
  $('a[@href*="love.htm"]').addClass('love');    
});

Attribute selectors accept regular-expression-like syntax for identifying the beginning(^), ending($), and asterisk(*) to indicate an arbitrary position within a string.

Now, you may get like this:



Series this article:
jQuery - Selectors: Understanding The $() Factory Function
jQuery - Selector: Modifying Style at List Item Levels
jQuery - Selector: Styling Sub Level Item
jQuery - Selector: XPath Selectors
jQuery - Selector: Custom Selectors
jQuery - Selector: Choose a Style at Custom Selectors
jQuery - Selector: Modify Style for Table Header
jQuery - Selector: Styling Sibling
jQuery - Selector: Styling Next Cell

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting