/    Sign up×
Community /Pin to ProfileBookmark

Simple Mouseover and MouseOut Effect

I’m having a little brain wreck here. I haven’t done image rollovers in a while. But I’m trying to change the background of an image when the mouse rolls over a <div> and then change it back to the original image when the mouse rolls out.

The code I have is doing something but it isn’t the right solution.

[CODE]

function highlightArrows(){

var arrow_div_left = document.getElementsByClassName(‘arrow-left’)[0];
var arrow_div_right = document.getElementsByClassName(‘arrow-right’)[0];

arrow_div_left.style.backgroundImage=”url(‘images/arrow-out-left-skyblue.png’)”;
arrow_div_right.style.backgroundImage=”url(‘images/arrow-out-right-skyblue.png’)”;

}

function replaceImages(){

var arrow_div_left = document.getElementsByClassName(‘arrow-left’)[0];
var arrow_div_right = document.getElementsByClassName(‘arrow-right’)[0];

arrow_div_left.style.backgroundImage=”url(‘images/arrow-out-left.png’)”;
arrow_div_right.style.backgroundImage=”url(‘images/arrow-out-right.png’)”;

}

[/CODE]

[code=html]

<div class=”gallery-thumbs-wrapper” onmouseover=”highlightArrows()” onmouseout=”replaceImages()”>
</div>

[/code]

I’m missing something in the JS code and can’t figure out what it is. The replaceImages() is suppose to return the image to its original pic. Any suggestions?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @ChuckB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...