From: Kim H. <kim...@vi...> - 2005-07-07 14:04:00
|
While unittesting some advanced dynamic table code, I mentioned some weird things going on. It took me a while to pinpoint the situation, but I've got it. It appeared to be reproducable using a very simple table which I grabbed from the HTMLUnit homepage. The problem is that after removing a tbody from a table using removeChild, the rows inside are still accessable throug document.getElementById(rowId), which unfortunately isn't acceptable. This code passes in 'any' browser, but throws a TypeError in my Unittest using HTMLUnit. The code I used to simply reproduce the strange behaviour: <html> <head> <title>Table sample</title> </head> <body> <table id="table1"> <caption>My complex table</caption> <thead> <tr> <th>Number</th> <th>Description</th> </tr> </thead> <tfoot> <tr> <td>7</td> <td></td> </tr> </tfoot> <tbody id="body1"> <tr id="row1"> <td>5</td> <td>Bicycle</td> </tr> </tbody>> <tbody id="body2"> <tr id="row2"> <td>2</td> <td>Tricycle</td> </tr> </tbody>> </table> <script type="text/javascript" language="JavaScript"> var table = document.getElementById('table1'); table.removeChild(document.getElementById('body1')); table.removeChild(document.getElementById('body2')); if (document.getElementById('row1') != null) { throw new TypeError('row should be null by now!!'); } </script> </body> </html> |