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

OnMouseOver does not change color

P: 93
Hi

Why the code below does not change the color. I can only see the pointer change only but it does not change the color?

Please help and Thnaks

nma

[HTML]<td width="100" height="17"><a href="some.html" onmouseover="document.t6.src=Image3.src;" onmouseout="document.t6.src=Image2.src;"><img name="t6" src="Highlight.jpg" width="100" height="17" border="0"></a></td>[/HTML]

on the declaration...
<SCRIPT LANGUAGE="JavaScript">

Image1 = new Image
Image2 = new Image
Image3 = new Image

Image1.src="nonHighlight.jpg";
Image2.src="Highlight.jpg";
Image3.src="Highlight-red.jpg";
</script>
Jan 16 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Change the new image declarations to 'new Image();'.

Use the document.images array:
[html]<td width="100" height="17"><a href="some.html" onmouseover="document.images['t6'].src=Image3.src;" onmouseout="document.images['t6'].src=Image2.src;"><img name="t6" src="Highlight.jpg" width="100" height="17" border="0"></a></td>[/html]
Jan 16 '08 #2

P: 93
nma
Hi Again,

I try the code but it change the color at wrong cell. When at cell t2 is mouseover but then cell t2 at second row change the color. Why it is happens?


Declaration..

Image1 = new Image();
Image2 = new Image();

Image1.src="Highlight.jpg";
Image2.src="Highlight-red.jpg";


Expand|Select|Wrap|Line Numbers
  1. <tr cellspacing="0" border="0" cellpadding="0">
  2. <td align="right" class="timelinebar_text">Exciting</td>    
  3. <td width="10" height="17" ><img name="t1" src="nonHighlight.jpg" width="10" height="17" border="0"></td>
  4. <td width="20" height="17"><a href="some.html" onmouseover="document.images['t2'].src=Image2.src;" onmouseout="document.images['t2'].src=Image1.src;"><img name="t2" src="Highlight.jpg" width="100" height="17" border="0"></a></td>
  5.  
  6. .......
  7.  
  8. </tr>
  9. <tr cellspacing="0" border="0" cellpadding="0">
  10. <td  align="right" class="timelinebar_text">Montage</td>    
  11. <td width="10" height="17"><img name="t1" src="nonHighlight.jpg" width="10" height="17" border="0"></td>
  12. <td width="100" height="17"><img name="t2" src="nonHighlight.jpg" width="100" height="17" border="0"></td>
  13. .......
  14.  
Jan 17 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Hi Again,

I try the code but it change the color at wrong cell. When at cell t2 is mouseover but then cell t2 at second row change the color. Why it is happens?
Because you've given them the same name, so it uses the second image with name t2. Give each image a unique name, or if not, give them a unique id and then access them using document.getElementById(imageID) instead.
Jan 18 '08 #4

P: 93
nma
Because you've given them the same name, so it uses the second image with name t2. Give each image a unique name, or if not, give them a unique id and then access them using document.getElementById(imageID) instead.

Thank you so much :)

nma
Jan 18 '08 #5

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad it helped.
Jan 18 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.