Click to See Complete Forum and Search --> : innner html thing mentioned in "goodies to go"


SabbathCat
12-11-2002, 10:17 AM
*** This question was submitted to our Mentor Community. The answer
was provided by Taylor Smith.

Q. I would like to know if it is possible to make an image open in a
particular table of a cell from a link in another cell. Kind of like
with
frames where you tell it to open in a TARGET frame.

A. If you give a cell a <span> with a name you can access it with
cellname.innerHTML="New Stuff".
For example
<table>
<tr>
<td><a onclick="magiczone.innerHTML='Look here now!'">Click to change
something.</a></td> <td><span name="magiczone">Pretty boring over
here.</span></td> </tr> </table>
When someone clicks the link the text changes. You can use <span> like
that
anywhere in your files.


All I get is a script error when I run it. On looking up InnerHTML on google, I get a whole bunch of conflicting stuff, involving everything from c# to shtml :P

What's the deal there, has anyone else had issuse, does it need some other code piece that was missing?

It sounds like a really useful bit of code if it worked :D

cheers

John

gil davis
12-11-2002, 11:44 AM
<td><a onclick="magiczone.innerHTML='Look here now!'">Click to change something.</a></td> <td><span name="magiczone">Pretty boring over here.</span></td>
More W3C DOM compliant:

<td><a href="#" onclick="document.getElementById('magiczone').innerHTML='Look here now!';return false">Click to change something.</a></td> <td><span id="magiczone">Pretty boring over here.</span></td>

Don't expect it to work in NS 4.X or below.