[function].apply() causing “JScript object expected” error in IE

box33

New Member
The following line of code causes a "JScript object expected" error in IE:\[code\]hideElements.apply(window, elements);\[/code\]According to IE, the 'expected JScript object' refers to \[code\]hideElements\[/code\], which is a function that takes any number of HTML objects as arguments and hide them.Concretely, I retrieve an array of HTML objects via a call to \[code\]getElementsByTagName\[/code\], and I would like to pass this array as a list of arguments to the function \[code\]hideElements\[/code\]. The JS function \[code\]apply()\[/code\] is exactly what I need in that case. I know I could surely write my code differently, but since this works perfectly on Firefox and Chrome, and is technically correct, I'd really like to know why IE gets stuck there.I've determined that, when the line is executed:
  • \[code\]window\[/code\] is not null and of type \[code\]Window\[/code\];
  • \[code\]elements\[/code\] is not null and of type \[code\]HTMLCollection\[/code\]; and
  • \[code\]hideElements\[/code\] is a fully functional JS function (that works perfectly on its own and that is fully loaded when the code above is executed).
 
Top