I was wondering if anyone can point me in the direction of a tutorial to help me out with my issue?
I have a div with a plain background image. Inside the div is some text. I would like the background image of the div to change when I mouse over the text within the div.
Thanks for anyone who can help me find a tutorial (or give me the code if they feel kind!) I am not havnig much luck looking in google.
I stumbled upon the solution you're looking for while searching for something completely different...
in your header tag, insert this javascript.
<script language="javascript" type="text/javascript"><!-- var ns = (document.all)?false:true; var intBack = 1;
//function for dynamically switching the background image function changeBg(divId,intBack) { if (ns){ layerObject = document.getElementById(divId).style; } else { layerObject = eval(divId + ".style"); } layerObject.backgroundImage = 'url(homebkgd'+intBack+'.jpg)'; } // --></script>
Then, in your text, you'll have a text link like so: <a href="#" class="linkSidebarU" onmouseover="changeBg('myDiv','3')">Mouseover to change background</a>
It'll call the change fuction called ChangeBG and will apply it to the div with the id "myDiv" (this would change to the id of your div with the background), then call the background "number" or in this case the image that you want to change it to.
If you need help integrating this, or adding features, let me know.
ok dont even put a div inside that dummy link - just make that <a> tag look however you want. In order to do that you have to make the <a> tag display:block, and then you can CSS it however and treat it like a div. Always avoid using "IE7 scripts" whenever possible. Also, as for the prior post of loading jQuery, do not do this unless you need to. the straight up easy JS code to do what you ask is
Why would you say "Always avoid using 'IE7 scripts' whenever possible"?
You cannot just make an anchor tag be treated like a div. Since an anchor is an inline element, you cannot have any block level elements be children of it. And why would you add an inline onmouseover attribute to the div? The whole idea is to avoid having inline events to junk up the mark up. You might as well just use a table for layout.