redho home | products | services

Programming Forums


Community for Java, PHP, Perl C, ASP and Python programmers

Ask your IT question here

OnMouseOver



 
Post new topic   Reply to topic    Programming Forums -> JavaScript forum
View previous topic :: View next topic  
Author Message
Krabik
Enthusiastic Coder


Joined: 15 Mar 2005
Posts: 62
hey, I want to be able to change text to an image when the user puts thier mouse over it, is this possible without using another image instead of text?? Anyone know how?

Reply with quote
 
Jake
Enthusiastic Coder


Joined: 15 Mar 2005
Posts: 68
There's a couple ways to do it, one would be to use the onmouseover event on a div containing the text, then use .innerHTML to change the contents of the div to an image, and back again for the mouseout.
Reply with quote
 
Krabik
Enthusiastic Coder


Joined: 15 Mar 2005
Posts: 62
could you give me a sample code possibly?? I'm still a bit confused.
Reply with quote
 
Jake
Enthusiastic Coder


Joined: 15 Mar 2005
Posts: 68
This is about a medium complex way to do it.

This goes in the HEAD:
Code:
<script type="text/javascript">
function swapimg(d,i) {
this.innerHTML = '<img src="' + i + '" />';
}
function swaptext(d,s) {
this.innerHTML = s;
}
</script>


This in the BODY:
Code:
<div id="d1" onmouseover="swapimg('d1','myimage.gif');" onmouseout="swaptext('d1','Something');">Something</div>

Reply with quote
 
Page 1 of 1
Post new topic   Reply to topic    Programming Forums -> JavaScript forum


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group