I’m trying to retrofit a page to read from XML rather than the DOM, and I’d rather not use $(xml).find(‘blah’) for every single call, and I was wondering if there was a way to point jQuery at xml, rather than the DOM.
For instance, I’d like to be able to navigate my xhtml with the jQuery method as such:
$(‘blah’).whatever
Is this possible?
No, you cannot redirect the global
documentobject to point to an arbitrary DOM document you’ve created.jQuery has given you the
contextargument to the$()function for exactly this purpose, so you should just use that:Or you can store it in a var to reduce repetition if you like, and traverse downwards from there: