Page 1 of 1

[js] Change text in a td or div (easily)? ::solved::

Posted: Sun Sep 04, 2005 10:08 pm
by Skara
Same project as my other thread, but a different problem. I don't know where to start...

Ok, I have a bunch of rooms where you can mouse over things and go places. Anyway, I want to change the text of a td or div when you mouse over and off of certain images.
e.g.
You mouse over the lamp and the td's text changes to "Lamp." You mouse off and the td goes blank again.

The only way I know how to do this is to make a bunch of divs that appear and disappear. Problem with that is It'd take a whole lot more coding and a bunch of divs laying around.

I need something like this:
onmouseover="appear('string');"
...
<td name="infobox">[blank until mouseover]</td>

Posted: Sun Sep 04, 2005 10:32 pm
by feyd

Code: Select all

function appear(text) {
  document.getElementById('mbox').innerHTML = text;
}

function disappear() {
  document.getElementById('mbox').innerHTML = '';
}
------
<div id="mbox"></div>
------
<a href="#" onmouseover="appear('I\'m supa-coo!');" onmouseout="disappear();">blah</a>

Posted: Mon Sep 05, 2005 7:41 am
by Skara
haHA! Nifty. Thanks!