I\'m trying to use jQuery inside a Firefox extension, and actually want to use jQuery to manipulate the DOM of the current page, as opposed to the context of the XUL file. T
Another way of doing it is overriding the constructor:
var initjQuery = jQuery.fn.init;
$.fn.init = function(s,c,r) {
c = c || window.document;
return new initjQuery(s,c,r);
};
var jQueryInit = $.fn.init;
$.fn.init = function(arg1, arg2, rootjQuery){
arg2 = arg2 || window.document;
return new jQueryInit(arg1, arg2, rootjQuery);
};
.trim(), .ajax() etc are static methods, meaning they are bound to the jQuery constructor and not it's prototype.
jQuery.noConflict();
$ = function(selector,context){ return new jQuery.fn.init(selector,context||example.doc); };
$.fn = $.prototype = jQuery.fn;
jQuery.extend($, jQuery); // copy's trim, extend etc to $
However a perhaps nice way is to leave jQuery intact and do the following:
var fromDoc = $(document);
// and if you want to find stuff:
fromDoc.find('div').doSomething();
fromDoc.find('.someClass').doSomethingElse();
This is also an optimisation since the context doesnt have to be manually set anymore with each query.