Hello,
I am trying to set an onClick event handler dynamically for a TD element in my document. Here is the code I am using, which is part of a function called “tabAction”:
[CODE]
var num = 0;
var myObjColl2 = getElementsByClassName(‘slidertabs’, ‘td’, cont);
for (var i = 0, j = myObjColl2.length; i < j; i++) {
num = Right(myObjColl2[i].id, 1);
myObjColl2[i].onclick = function() {tabAction(true, myObjColl2[i], ‘menu’ + num)};
The getElementsByClassName function does just what the name implies, and returns an array of elements that have that className.
The TD element originally contains the following onClick event handler as:
[CODE]<td align=”center” valign=”middle” id=”slider1″ onclick=”tabAction(true, this, ‘menu1’);” class=”slidertabs”>
Everything seems to work OK except after the code runs. When I click on a TD element that has been updated, I get an error message:
[B]‘Undefined’ is null or not an object
I think I have narrowed the problem down to the [B]myObjColl2[i]
[CODE]myObjColl2[i].onclick = function() {tabAction(true, myObjColl2[i], ‘menu’ + num)};
How can I refer to the element object from which the function is called if I am assigning it dynamically?
Thanks for any help!