Bergi (stack overflow user) so graciously helped me come up with a solution for image swap using jQuery. It swaps on hover now, but id like to make it so that it stays highlighted on your current sub site (for example, I click on “Comics” page, and “Comics” stays highlighted). Is that possible? Thanks!
<script type="text/javascript">
var images = {
"comicssubsite": [
"./images/SiteDesign/Comics_subsites_hover.png",
"./images/SiteDesign/Comics_subsites.png"
],
"artworksubsite": [
"./images/SiteDesign/Artwork_subsites_hover.png",
"./images/SiteDesign/Artwork_subsites.png"
],
"aboutsubsite": [
"./images/SiteDesign/About_subsites_hover.png",
"./images/SiteDesign/About_subsites.png"
],
"blog": [
"./images/SiteDesign/Blog_othersites_hover.png",
"./images/SiteDesign/Blog_othersites.png"
],
"facebook": [
"./images/SiteDesign/Facebook_othersites_hover.png",
"./images/SiteDesign/Facebook_othersites.png"
]
};
jQuery(document).ready(function($) {
$("#comicssubsite, #artworksubsite, #aboutsubsite, #blog, #facebook").hover(function(e) {
// mouseover handler
if (this.id in images) // check for key in map
this.src = images[this.id][0];
}, function(e) {
// mouseout handler
if (this.id in images)
this.src = images[this.id][1];
});
});
Zotal Toth’s answer should work, but you should consider changing your mouseout-handler like so, unless you want the image to change back, once a user hovers over it: