By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,567 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,567 IT Pros & Developers. It's quick & easy.

onMouseOver to change/hide text

P: n/a
Hello,

I am trying to change a piece of text using onmouseover. I have tried a few
things so far and nothing has really worked. I get get a new piece of text
to appear but bastardizing someone elses code, but can't figure out how to
hide the other one....

I sort of have the following but don't know if this is close to the best way
of doing it really...

Basically I want to have a piece of text, lets say TEXT1, that changes from
blue to red, and to TEXT2 while the mouse is over it.

I know nothing really about Java so have had a look around but got no
futher. Any help would be great.

Cheers


<html>
<head>
<script type="text/JavaScript">
function setText(t){
if(document.layers)
{
with(document.layers["myDiv"].document)
{
open();
write(t);
close();
}
}
else if(document.all)
{
myDiv.innerHTML = t;
}
}
</script>
</head>
<body>
<a href="#"
onmouseover="setText('test2)",
onmouseout="setText('')">test1</a>&nbsp;
&nbsp;<br>
<div style="position:absolute;top:14;left:11;width:100; " name="myDiv"
id="myDiv"></div>
</body>
</html>


Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You might try this too:
<p onMouseOver="this.style.color='#FF0000', this.innerHTML='The Text
Changed' "
onMouseOut ="this.style.color='#000000', this.innerHTML='Change My
Color' "

Change My Color
</p>

Jul 20 '05 #2

P: n/a

"SanJoseWebGuy" <sa***********@aol.com.nospam> wrote in message
news:20***************************@mb-m06.aol.com...
You might try this too:
<p onMouseOver="this.style.color='#FF0000', this.innerHTML='The Text
Changed' "
onMouseOut ="this.style.color='#000000', this.innerHTML='Change My Color' "

Change My Color
</p>


Thanks for the tip. Sorry, thought I can't get it to work.. What else do I
need with your snippet? I really don't know javascript at all..

Cheers
Jul 20 '05 #3

P: n/a

"SanJoseWebGuy" <sa***********@aol.com.nospam> wrote in message
news:20***************************@mb-m06.aol.com...
You might try this too:
<p onMouseOver="this.style.color='#FF0000', this.innerHTML='The Text
Changed' "
onMouseOut ="this.style.color='#000000', this.innerHTML='Change My Color' "

Change My Color
</p>

Sorry to be such a pain, but that looks like it should do what I want, but
when I paste it into a n HTML document, it displays "Change My Color", but
doesn't actually do anything.

Do I need to define style or colour, or innerHTML somewhere?

Thanks
Jul 20 '05 #4

P: n/a
"CQMMAN" <cq****@yahoo.co.uk> writes:
"SanJoseWebGuy" <sa***********@aol.com.nospam> wrote in message
news:20***************************@mb-m06.aol.com...
<p onMouseOver="this.style.color='#FF0000', this.innerHTML='The Text
Changed' "


I would change the "," to a ";". While legal, commas are used to
separate expressions (and evaluates to the last expression) while
semicolons are used to to end statements. In the above, the value of
the second (assignment-)expression is not relevant, so it's more
appropriate to treat it as a statement.
Sorry to be such a pain, but that looks like it should do what I want, but
when I paste it into a n HTML document, it displays "Change My Color", but
doesn't actually do anything.
Does it give a Javascript error message? Have you turned Javascript error
messages on? (If not, do so!)

I can see your quote has line breaks all over the place. You can not
have line breaks inside Javascript strings, so try putting more of it on
one line.

It works for me if I do.
Do I need to define style or colour, or innerHTML somewhere?


No, they already exist on the element.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

P: n/a

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:wu**********@hotpop.com...
Does it give a Javascript error message? Have you turned Javascript error
messages on? (If not, do so!)

I can see your quote has line breaks all over the place. You can not
have line breaks inside Javascript strings, so try putting more of it on
one line.

It works for me if I do.


Aaahhh.. Yes, linewrap.... Thanks very much for your help..

Cheers
CQMMAN
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.