This is a discussion on "[SOLVED] Change div background on hover of another element" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Change div background on hover of another element are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] Change div background on hover of another element
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
||||
|
[SOLVED] Change div background on hover of another element
Is there a script out there that can dynamically change the background of a div to various images, depending on which element is 'hovered' or mouse-overed elsewhere on the page?
In short, I want a div at the bottom of my page to switch between preset background images based on the navigation tab at the top that the user hovers over Many thanks Alex
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
|
|
|
|||
|
Re: Change div background on hover of another element
Should be easy. Without loss of generality, let's say you want to change the background of <div id="swap"> when the mouse is over <div id="hover">. Use this javascript:
|
|
||||
|
Re: Change div background on hover of another element
Sorry Mike, no go. I wouldn't know what to change, I'm a javascript amateur
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
|
|||
|
Re: Change div background on hover of another element
Quote:
|
|
|||
|
Re: Change div background on hover of another element
Have you got a link to your web page so we can give you an example?
Basically what you would do is: (If anything is wrong, please correct me)
You then place that whole piece of code somewhere in between the <head> </head> section of your webpage. |
|
||||
|
Re: Change div background on hover of another element
Code uploaded at http://www.neilraymond.co.uk/test/test.htm
Just can't make it work EDIT: I'm getting a javascript error
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
Last edited by Aso; Dec 7th, 2007 at 23:24. |
|
|||
|
Re: Change div background on hover of another element
As I said, I might have messed up the first (abstracted) version. Have you tried my second set of code?
You can also debug the code by placing the line alert("break") at various points. That tells you how far the code got. |
|
||||
|
Re: Change div background on hover of another element
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
|
|||
|
Re: Change div background on hover of another element
Right, I've had to change the code a bit. But it works now.
I then used a event handler on the link (onmouseover="swapImage('swapDiv','tartan.png')") to trigger the function. |
|
|||
|
Re: Change div background on hover of another element
I almost never do this, but since you're so helpful to other members, here's something in return. Merry Christmas.
Working demo page. *edit* maybe not so useful now. Oh well, it's the thought that counts. |
|
||||
|
Re: Change div background on hover of another element
Thank you Mike & Blake. Really appreciate it
Merry Christmas indeed!
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] isolate clicks on the background of an element ??? | pesho318i | JavaScript Forum | 3 | Nov 21st, 2007 13:01 |
| [SOLVED] Change Input Textbox Background Color | tejaxx | JavaScript Forum | 4 | Nov 19th, 2007 20:16 |
| How To Active Hover? Where I have to Change? | opengiga | Web Page Design | 9 | Oct 5th, 2007 05:45 |
| change colour of text, on hover. | Jason3107 | Web Page Design | 28 | Sep 27th, 2007 23:10 |
| a:hover background chnage | gribble | Web Page Design | 1 | Aug 12th, 2005 19:29 |