I have some javascript that creates rows and cells in a table. The cell don't have anything in them. CSS sets a fixed width and heigth and a background color. For IE, I use attachEvent('onclick', click_handler). This works fine in IE up to version 7. I get no events in IE8. Below is a code sample: var table=document.getElementById('my_table'); for (var row=0; row<num_rows; row++) { var new_row = document.createElement('tr'); for (var col=0; col<num_cols; co++) { var new_col = document.createElement('td'); new_col.className = 'pixel_off'; new_col.width = pixel_size; new_col.height = pixel_size; new_col.attachEvent('onclick', click_handler); new_row.appendChild(new_col); } table.appendChild(new_row); }
Chris P Elliott <Chris P Elliott@discussions.microsoft.com> wrote: > I have some javascript that creates rows and cells in a table. The > cell don't have anything in them. CSS sets a fixed width and heigth > and a background color. For IE, I use attachEvent('onclick', > click_handler). This works fine in IE up to version 7. I get no > events in IE8. Below is a code sample: > > new_col.attachEvent('onclick', click_handler); > new_row.appendChild(new_col); Try putting these two lines the other way round. I don't know about IE8, but in FireFox one can't attach event handlers on an element that hasn't been inserted into DOM yet. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
I'm also worried about this... The onclick event is not working. "Chris P Elliott" wrote: > I have some javascript that creates rows and cells in a table. The cell > don't have anything in them. CSS sets a fixed width and heigth and a > background color. For IE, I use attachEvent('onclick', click_handler). This > works fine in IE up to version 7. I get no events in IE8. Below is a code > sample: > > var table=document.getElementById('my_table'); > for (var row=0; row<num_rows; row++) { > var new_row = document.createElement('tr'); > for (var col=0; col<num_cols; co++) { > var new_col = document.createElement('td'); > new_col.className = 'pixel_off'; > new_col.width = pixel_size; > new_col.height = pixel_size; > new_col.attachEvent('onclick', click_handler); > new_row.appendChild(new_col); > } > table.appendChild(new_row); > }
I got it down to a single line that causes IE8 to not handle onclick event for an empty cell. If I delete the first line on my page, it works: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/transitional.dtd"> I would rather not delete this line as much testing has been completed with other browsers. Any idea if Microsoft is planning to fix this one before release?