Whenever I try to replace anything in the DOM with innerHTML in
Safari, I get "(event handler):DOM exception 7" in the Console,
which means I'm not allowed to alter it.
Why should this be? There's a page on O'Reilly that charts dynamic
table generation
http://www.oreillynet.com/javascript/2003/05/06/examples/
dyn_table_benchmarker_ora.html which cites results for doing this, so
it must be possible.
Can anyone confirm this for me?
If you have a spare minute try the link above and hit the "Approach
#3" button to see if it works for you or not.
The problem is not that innerHTML doesn't work (it works fine), but
that Safari can't handle writing the innerHTML of a <tbody> tag. If
you write the entire table (including <table> and <tbody>) in the
innerHTML string it works fine.
See my tests at http://www.quirksmode.org/dom/innerhtml.html for a
working example. (Incidentally, I come to the opposite conclusion as
Goodman: innerHTML is faster than pure W3C DOM).
Ah, that was you :)
Your tests helped me a great deal in getting to grips with this DOM
thing, which is new ground for me.
Thanks for publishing, they really were very valuable indeed.
I've discovered some more weird behavior too, so let me explain what it
is that I'm trying to do.
I'm trying to replicate the behavior of a disclosure box, so that I can
hide a form inside it and have it shown when the user clicks the
disclosure triangle in the box, much like a Mac OS interface thing.
Using the W3C DOM method worked for me, but I discovered that once the
box had been closed and reopened, I couldn't reference any of the form
elements any more.
After trying many alternatives to grab a hold on the form elements
(id's, referring by index number on the form etc) I discovered that
part of the reason was to do with that when Safari removes the rows in
the table, it still has some internal reference to them somewhere.
So, everytime you close the box (remove the rows) then open the box
again, you are effectively adding more and more rows to the table (even
though you can only see the rows you've just added). In my case, if I
wanted to access document.form1[0] it'd be fine the first time the box
was opened, but subsequent times the index would be added to by the
number of elements in the box.
To remedy this, I tried your method of re-writing the entire table in
one go, and it works a treat.
I suspect all this has something to do with the problems of Safari
getting slower and slower everytime you repeated your tests - the first
time you rendered your table there were 50 rows, but on subsequent
repeat tests, Safari's internal representation of the table was
increasing by 50 rows each time.
Obviously these are quick and dirty tests, so forgive the lack of
comments etc.
Cheers
Ian
_______________________________________________
web-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/web-development
Do not post admin requests to the list. They will be ignored.