PDA

View Full Version : Javascript


colenielsen
11-05-2003, 12:16 PM
Start Pseudocode

onMouseOver {
change text encapsulated in a <div> tag to something different.
}

How can I accomplish this task?

As an example - I have an image that when I mouse over it, in a seperate DIV displays what that image is or where it links to.

Cole

whirlybird540
11-05-2003, 12:34 PM
Give the div an id. ie <div id="theDiv"></div>

Then in your script

document.getElementById('theDiv').innerText = "This is a link that goes somewhere";

colenielsen
11-05-2003, 01:03 PM
How compatible is this feature? In other words, 3.x, 4.x, IE, NS, Safari, Mozilla???

Willy Duitt
11-05-2003, 03:33 PM
Originally posted by colenielsen in this thread (http://www.htmlforums.com/showthread.php?s=&threadid=30701)
It's all good but I develop on an open-source platform
and intend to keep campatability to a maximum.

Your comments in this thread (http://www.htmlforums.com/showthread.php?s=&threadid=30701) would leave one to believe
that you understood getElementById is compatable with
version 5+ browsers while IE4 supports document.all
and NS4 supports document.layers

As for Safari, Mozilla. You also previously stated that
you routinely use those browsers. Therefore, maybe you
can enlighten me to their compatability with getElementByID.

Thanks;
....Willy

Vincent Puglia
11-05-2003, 05:37 PM
Hi,

Version 3s, if they still exist, do not allow 'dHTML'; therefore, you should redirect them prior to loading the page. InnerText is IE-only (IE4+, Aol)


function write2Div(divID, txt)
{
var divObj = (document.layers) ? document.layers[divID] : (document.all) ? document.all[divID] : document.getElementById(divID)

if (document.layers)
{
divObj.document.open();
divObj.document.write(txt);
divObj.document.close();
}
else
divObj.innerHTML = txt;

}

...onmouseover="write2Div('theDiv','some text here')">



Vinny

drspin
11-05-2003, 05:49 PM
<script language="javascript">
<!--
var x;
function init () {
x = document.getElementById('headNAVText');
}

function textSwap(stuff, text)
{
x[stuff] = text;
}

function clearX(prop)
{
x[prop] = '.';
}
-->
</script>

<body onLoad="init()">

<a href="javascript://" onMouseOver="textSwap('innerHTML', 'Some Text to try')" onMouseOut="clearX('innerHTML')" ><img src="images/navTEMP.jpg"></a>
<div id="headNAVText">Initial Text</div>


This works in Netscape, Mozilla, Safari and IE - doubt it works in 3.x browsers which I'm not REAL concerned with anymore as the whole site is done with CSS ;)

Cole