/    Sign up×
Community /Pin to ProfileBookmark

vertical menu with background image change on click but no page reload

I was wondering how to change the background image on a menu item with javascript without reloading the page. Then if you click another button on the menu the first button clicked would change back and then the second button would then become the one with the different background… here is my menu code:

[CODE]
<ul class=”menu”>
<li><a href=”/home” class=”imagelink lookA”><span>Home</span></a></li>
<li><a href=”/services”><span>Services</span></a></li>
<li><a href=”/about”><span>About</span></a></li>
<li><a href=”/contact”><span>Contact</span></a></li>
</ul>
[/CODE]

Here is my css code:

[CODE]
.menu{margin:0; padding:0; width:300px; list-style:none;background:rgb(255,255,255);}
.menu li{padding:0; margin:0 0 1px 0; height:40px; display:block; }
.menu li a{text-align:left;height:40px; padding:0px 25px; font:16px Verdana, Arial, Helvetica, sans-serif; ; display:block; background:url(‘../images/image1.jpg’) 0px 0px no-repeat; text-decoration:none; outline:none;}
.menu li a:hover{background:url(‘../images/image2.jpg’) no-repeat; }
.menu li a.active, .menu li a.active:hover{background:url(‘../images/image2.jpg’) no-repeat; }
.menu li a span{line-height:40px;}
[/CODE]

Thanks for the help!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Robmcmon 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 5.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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