Tip - Object doesn't support this property or method

Using Internet Explorer, if you get the error Object doesn't support this property or method when using Prototype or script.aculo.us, you've probably tried to use a Prototype/script.aculo.us method on an unextended DOM element, like this:

$('foo').nextSibling.remove();      // <== WRONG

That code is finding the element with the ID foo, then removing the sibling element that follows it. But it's trying to call the remove method on an unextended element.

This works on Firefox, Chrome, and other browsers where Prototype can extend elements by extending the prototypes of DOM elements in general, but it doesn't work on Internet Explorer because IE doesn't let you extend the prototypes of DOM elements, it only lets you extend (add methods to) individual element instances. (For more about this, see How Prototype Extends the DOM, but as of this writing that article is out of date and though conceptually correct, the code examples are outdated.) To extend an unextended element, pass it through the $ function. Our code above would do that like this:

$($('foo').nextSibling).remove();   // <== Right

Prototype automatically extends any elements you retrieve through its API, so we wouldn't have had to worry about this at all if we'd used Prototype's {{next}} method instead of the DOM nextSibling property:

$('foo').next().remove();           // <== Also right
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License