473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

onMouseOver to change/hide text

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
5 10888
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

"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

"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
"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim | last post by:
Hope someone in the big wide world can help... What I want to do is have an image slideshow which automatically scrolls through a series of images very fast, then pauses when you move your mouse...
7
by: Richard | last post by:
I know I can have like <a href="#" onclick="dothis" onmouseover="dothat"> But how do you properly code two mouseover's in one statement? <a href="#" onmousever="dothis" onmouseover="dothat"> As...
5
by: Jake | last post by:
What would be the correct syntax for setting the z-index of a layer OnMouseOver? I have a mouseover action on a visible layer which displays a popup info layer but it gets displayed behind other...
12
by: Epetruk | last post by:
Hi all, I want a page where the contents of a table cell are replaced with an image when the mouse moves over the cell, and the text is restored when the mouse moves out. Here's the html for the...
5
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything...
4
by: Rob R. Ainscough | last post by:
I'm using .NET v1.1 with ASPX web page. I'm trying to have a RollOver hyperlink that will change images on an image control and update the text in a Label control. I've got the image swapping...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
2
by: flash | last post by:
1-When the mouse is over the course title. Its description should appear. When it the mouse is out, the description should disappear. 2-when double click on a word, its color changes to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.