PDA

View Full Version : javascript: changing td background images


tommeh
05-25-2004, 02:58 PM
ok, I have a simple problem, but first I just want to let you know that I am completely unfamiliar with javascript. I only need it to do the function that I will explain later. I am fluent in html, css, and php, but I dont think that any of these languages apply to my problem. Anyway...


what I want to do is have the background image of a td to change when the user hovers over the link that is inside the td. I do NOT want the td bg image to change when the user hovers over the td; i only want it to change when they hover over the link. This is what I have so far

<td class=Navlink height=25 background=navtdbg.jpg name=homebg><div class=Navlink>&nbsp;<a href="guidance.php">Home</a></div></td>

Help?

agent002
05-25-2004, 03:18 PM
Hi Tommeh,
being familiar with PHP is a good advantage if you want to learn JavaScript. They're still pretty similiar languages, although they're used for different purposes.

If the link always is located inside a div, that is inside the td, you can use this short and simple code to do it:
onmouseover="this.parentNode.parentNode.style.backgroundImage = 'url(/path/to/filename.jpg)';"

If the link could be located somewhere else, you may need an id to refer to the td - at least other code. :)

tommeh
05-25-2004, 03:32 PM
GENIUS!!!

thank you very much, works exactly how I wanted it to. thank you thank you thank you