Book Image

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Book Image

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Overview of this book

Table of Contents (18 chapters)
Learning jQuery
Credits
About the Authors
About the Reviewers
Preface

XPath Selectors


XML Path Language (XPath) is a type of language for identifying different elements or their values within XML documents, similar to the way CSS identifies elements in HTML documents. The jQuery library supports a basic set of XPath selectors that we can use alongside CSS selectors, if we so desire. And with jQuery, both XPath and CSS selectors can be used regardless of the document type.

When it comes to attribute selectors, jQuery uses the XPath convention of identifying attributes by prefixing them with the @ symbol inside square brackets, rather than the less-flexible CSS equivalent. For example, to select all links that have a title attribute, we would write the following:

$('a[@title]')

This XPath syntax allows for another use of square brackets, without the @, to designate an element that is contained within another element. We can, for example, get all div elements that contain an ol element with the following selector expression:

$('div[ol]')

Styling Links

Attribute selectors...