I cooked up a pattern to create and extend html elements using their prototype. This works like a charm in non-ie browsers. Example code can be found @jsbin (see page source)
The advantage of this pattern should be speed (the methods are in the elements prototype chain, so they are referenced once). You guessed right: IE no go. In IE < 8 the prototype of html elements is hidden/not accessible, so for every element you create, you have to reference the non standard methods again (leaving you with a lot of pointers if you use the pattern intensively). I have searched the web for solutions, but only found complex workarounds. Is there really no way to access a HTML elements prototype in IE?
Element.prototype
and add methods to it. This is guaranteed by the latest version of the DOM Living Standard, which defines things likeElement
as WebIDL interfaces, which carries with it the explicit implication that they should be accessible in the global scope and their prototypes should be modifiable.document.getElementById('someelement').prototype
will throw aTypeError
; perhaps you could just delete it and then flag this comment of mine as obsolete for a mod to mop up?document.getElementById('some').prototype
returnsundefined
in IE8 (so, not aTypeError
),document.getElementById('some').constructor.prototype
returns the prototype.