jQuery

jQuery is something I’ve been wanting for a while now. It lets you use XPath and CSS selectors to manipulate the DOM in JavaScript. It’s got some quirks, but it’s vastly better than mucking around with getElementsByTagName() and loops. You can easily get the node(s) you want with one line of XPath instead.

It’s not perfect. I had some trouble using the attribute stuff in XPath (//li[ul]/a[@class="foo"] doesn’t seem to work in IE), and I wish there was a way to return a plain NamedNodeMap from a query instead of it’s crazy internal format. But it’s still terribly useful, and reasonably modular. I’ll definitely be doing some hacking on it; it’s a good base library to build more functionality on.

One Response to “jQuery”

  1. John Resig Says:

    Thanks for the great feedback!

    I imagine that the reason @class=”foo” doesn’t work is that IE doesn’t allow for access to class using the ‘class’ name. I think you have to use @className=’foo’ exclusively. Generally speaking, it’s better to leave the class stuff to the CSS syntax.

    The way to return an Array of the matched elements is by using the get() method, for example:
    $(”div p”).get();
    Some more info on that function, and similar, can be found here: jQuery Base Iterators.

    (btw, it’s good to see another film and Depeche Mode fan)

Leave a Reply