PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


jQuery - Selector: XPath Selectors


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


Tag: jQuery, $(), factory, function, selectors, XPath Category: JavaScript Post : March 21st 2008 Read: 2,805 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration