Closed Thread Icon

Topic awaiting preservation: I have a question about innerHTML and DOM (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=25526" title="Pages that link to Topic awaiting preservation: I have a question about innerHTML and DOM (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: I have a question about innerHTML and DOM <span class="small">(Page 1 of 1)</span>\

 
gunder
Obsessive-Compulsive (I) Inmate

From:
Insane since: Apr 2005

posted posted 04-15-2005 20:42

Hello everyone, I'm still learning javascript and want to try to keep everything compatible. I found something I want to play around and add to, you can look at the source here here if you want. Here is his body tag ..

code:
<body name="X" id="X" onLoad="DrawAll();" onkeypress="MainLoop();">



And at the end of his DrawAll funtion he has this ..

code:
X.innerHTML = output;



If I'm understanding it right, it's just redrawing the whole screen everytime something happens right? From what I can find out innerHTML isn't standard, is that correct or am I missunderstanding something? Also, would there be a way to update only the parts of the screen that need to be updated instead of redrawing it all? If these are really stupid questions I apologize ahead of time.


-gunder

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 04-15-2005 21:07

You're correct, innerHTML isn't standard: it's an MSIE extensions that's been adopted by all major browsers.

Basically, what innerHTML does is it changes the HTML inside of a tag to whatever string you make it.

Say I have this:

code:
<div id="foo">Hello, <b>I am</b> a <i>crazy</i> tag!</div>



If I did this in Javascript:

code:
document.getElementById("foo").innerHTML = "<a href='http://www.google.com/'>wee!</a>";



Then it would change that div to effectively being:

code:
<div id="foo"><a href='http://www.google.com/'>wee!</a></div>



---
Website

gunder
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2005

posted posted 04-16-2005 18:56

Thanks for the reply, I thought that's what it did. Even though it has been adopted by most browsers, is there a better way to do it that is standard? I don't know if I'm making a big deal out of nothing, I just want to keep to the standards as much as possible.

-gunder

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 04-16-2005 21:26

The standard way to do it is using DOM methods; things like createElement, appendChild, setAttribute, etc. An example I've done can be found at http://www.rpi.edu/~laporj2/art/dynamic/javascript/pandachase/index.html , though the code is short, it's somewhat complex, so it may not be the best example.

A handy reference I use, specific to Gecko, is at: http://www.mozilla.org/docs/dom/domref/

It does have reference of things not standard (such as innerHTML), but will always note whether or not they are.

---
Website

« BackwardsOnwards »

Show Forum Drop Down Menu