tags:

views:

23

answers:

1

I've defined method fadeIn for Object


Object.prototype.fadeIn = function(d, callback) { //some code here };

....

var b = documentGetElementById('b1'); // <div id="b1"></div>
b.fadeIn();

It works in FF, Opera, Chrome, but IE reports "Object doesn't support this property or method" when I try launch fadeIn. Why IE doesn't inherit my methods from Object and how to fix it?

+3  A: 

In IE, DOM nodes do not inherit from Object.prototype. They're not obliged to; as host objects (i.e. objects provided by the environment) they can essentially do what they like. I recommend reading Juriy Zaytsev's excellent article about extending the DOM.

The simple solution is to write a function that accepts an element as parameter:

function fadeIn(el, d, callback) {
    // Implementation code
}

var b = document.getElementById('b1');
fadeIn(b);
Tim Down
thanks for link
Yrgl