Monday, September 19th, 2005

cssQuery: cross-browser JavaScript querying

Category: Library

We have pointed you to Dean Edwards’ package called IE7 in the past.

Now, he has released cssQuery():

cssQuery() is a powerful cross-browser JavaScript function that enables querying of a DOM document using CSS selectors. All CSS1 and CSS2 selectors are allowed plus quite a few CSS3 selectors.

Usage / Examples

elements = cssQuery(selector [, from]);

// find all paragraphs that are direct descendants
// of the document body
var tags = cssQuery(“body > p”);

// find all elements with the “href” attribute
var tags = cssQuery(“[href]”);

// find all anchor elements with “href” equal to “#”
var tags = cssQuery(“a[href=’#’]”);
// find all images contained by the above anchors
var images = cssQuery(“img”, tags);

// find all lists
var tags = cssQuery(“dl,ol,ul”);

// query an external xml document
var tags = cssQuery(“my|:root>my|link”, myXMLDoc);

// just plain complicated
var complex = “p>a:first-child+input[type=text]~span”;
var tags = cssQuery(complex);

Download cssQuery package

Posted by Dion Almaer at 9:08 am
Comment here

3 rating from 5 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.