I'd like to modify all jQuery functions, which return object with DOM elements, with some additional data, so whenever I'd call jQuery functions, which return jQuery object with DOM elements, like $(selector)
, find
, filter
, etc. and would normally get a standard jQuery object:
{ 0: DOMElement1, 1: DOMElement2, 2: DOMElement3, ...}
i'd like to get a modified jQuery object instead, e.g.:
{ 0: {0: DOMElement1, num: 1}, 1: {1: DOMElement2, num: 2}, 2: {2: DOMElement3, num: 3}}
I tried to modify the $.fn.constructor
:
(function($) {
var orig = $.fn.constructor;
$.fn.constructor = function(e) {
var origApplied = orig.apply(this, arguments);
console.log("Constructor called");
var outputData = $.map( origAppliedArray, function (value, index) { return {[index]: value, num: index} });
return outputData;
}
})(jQuery)
The constructor is called every time the find
or filter
functions are called, but the code only returns an array with DOM elements.
How could I achieve the mentioned result?