Forum Moderators: open

Message Too Old, No Replies

Do you use InnerHTML?

why or why not?

         

webdevsf

1:32 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



It is so much more convenient than using the DOM, and it is supported by IE, Moz, Opera, etc, that it feels like a part of the standard (even though its not).

A good reason that i know not to use it is because it is difficult to grab a handle to any objects you create with innerHTML. But that can easily be solved with a getElementById.

So, (assuming you are supporting DHTML in your code) are you using innerHTML? If not, why not?

DrDoc

3:06 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it depends on what I need to do...

If I need to copy content, modify, and then put it somewhere else, I use the DOM (cloneNode, parentNode, childNodes)... It works the best, and is easiest to modify.

Otherwise, if it's just a matter of replacing some existing content with something else I use innerHTML, mainly because that path is so much faster.

Take a look at this: [quirksmode.org...]

Even though I find the DOM stats a little bit skewed (it depends very much on the amount of content you are working with, and how fast your computer is) there is no doubt innerHTML is faster.