View Full Version : Node.prototype to work in IE

10-17-2005, 04:26 AM
Node.prototype doesn't seem to work in Internet Explorer.

Is there something else I can use for Node, that works in Internet Explorer 5+ ?

10-17-2005, 08:58 AM
What is your final goal, after all? What are u looking after? can u detail a little bit?

10-17-2005, 09:26 PM
Sorry for not providing enough information, this here is my function:

Node.prototype.setAttributes = function()
for( ar = 0 ; ar < arguments.length ; ar=ar+2 )
(arguments[ar] == 'class')? this.className = arguments[ar+1]:this.setAttribute(arguments[ar],arguments[ar+1]);

It would set multiple attributes to a Node on one line, I know it can be done with normal functions, but I just wanted to know if I can do it with prototype.
The problem here is that Internet Explorer does not define "Node", it works fine in Firefox (don't know about other browsers), so is there anything else I can use instead of "Node" for it to work in Internet Explorer and other browsers?

10-17-2005, 10:29 PM
The IE DOM does not allow JavaScript to access the DOM constructors for prototyping and hence HTML element/Node prototyping is not supported by the IE DOM natively, it must be emulated. jkd wrote an interesting article on it here for IE 5.5+: http://blog.codingforums.com/index.php/main/blogentry/element_prototyping_in_internet_explorer_55_and_above/

I would suggest using string manipulation/concatenation to set multiple values to a node attribute, potentially having to use multiline code to do this.

Or do something like this:
// top level function rather than prototype
function setElementAttribute(obj, attributeName, attributeValue) {
obj.setAttribute(attributeName, attributeValue);

// usage
setElementAttribute(document.getElementById("elementID"), "customAttribute", "martin_narg 29 London");

Hope this helps


10-17-2005, 11:42 PM
That's what I was afraid I was going to have to do :(

Stupid IE >_>, thanks anyways :thumbsup: