[jQuery] Copying HTMLElement methods in IE

[jQuery] Copying HTMLElement methods in IE


This might be kind of a niche thing, but anyways... I'm trying to
extend jQuery so that if $() returns a single element, you can get the
element's properties directly on the jQuery instance. e.g.
$('#something').tagName // "DIV"
$('#something').style.color = '#f00';
$('#something').getElementsByTagName('p')
(I know, these are contrived examples but I'm trying to get this to
work for a new library I'm developing.) The first two work in FF and
IE, but the last one fails in IE -- it seems IE doesn't expose its
methods on DOM nodes. Here's the code I'm using to make this work...
// Augment jQuery so that HTMLElement properties and methods
// are available to call directly on singular collections
jQuery.prototype._init = jQuery.prototype.init;
jQuery.prototype.init = function() {
var result = this._init.apply(this, arguments);
this.addDomProperties();
return result;
};
jQuery.prototype.addDomProperties = function() {
if (this.length != 1) return;
var element = this[0], value;
try {
for (var property in element) {
if (this[property]) continue;
value = element[property];
this[property] = (typeof value == 'function') ?
function() { return
arguments.callee._method.apply(element, arguments); } :
value;
if (typeof value == 'function')
this[property]._method = value;
}
} catch (e) {}
};
Does anyone know if it's possible to get all the DOM methods of an
element in IE without writing out wrappers for all the ones I can list
by hand?