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?
Advertisements. The Element object provides various utility functions for manipulating elements in the DOM. Here is the list of all the utility functions with examples. All the methods defined here are automatically added to any element accessed using the $() function.
An HTMLCollection in the HTML DOM is live; it is automatically updated when the underlying document is changed.
An HTMLCollection is a collection of document elements. A NodeList is a collection of document nodes (element nodes, attribute nodes, and text nodes). HTMLCollection items can be accessed by their name, id, or index number. NodeList items can only be accessed by their index number.
The NodeList elements are only accessible by a numeric index. Both NodeList and HTMLCollection are not arrays, so you can not use the array methods like push() , pop() , join() , and valueOf() for both of them.
No, nor is it guaranteed you can fiddle with DOM objects' prototypes in JavaScript in general. The DOM objects are not part of the ECMAScript spec; they may not be (and traditionally speaking aren't) native JavaScript Objects at all, in any browser.
This is why frameworks tend to have their own ‘container’ wrapper classes.
Also you cannot rely on ‘t.el.constructor’ even if they were native JS Objects. ‘constructor’ is not a standard property, isn't available in IE, and even in Mozilla doesn't do what you might think it does. Avoid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With