> jQuery.fn.find=function( selector ) { > this.query=selector; //this is the only line you have to modify > > var elems = jQuery.map(this, function(elem){ > return jQuery.find( selector, elem ); > }); > return this.pushStack( /[^+>] [^+>]/.test( selector ) || > selector.indexOf("..") > -1 ? > jQuery.unique( elems ) : elems ); > > } > > Now you can get the query string: > $('body .class').prevObject.query //->'body .class' > $('body').find('.class').prevObject.prevObject.query //->'body' > but > $('#id').prevObject.query //->undefined > $().find('#id').prevObject.query //->'#id'
here is the final tweak, (after adding this modified find method) query = (this.prevObject && this.prevObject.query) || this[0]; I strongly believe that such property should be added to the main distro of jQuery. After all, the idea of find-and-modify approach - one of jQuery fundamentals.