I wrote a script to change a static image by hovering over navigation links. It works great, however, the script is very long and I'm guessing there is a much more efficient way to write this code. Can anyone give me tips on a better way to do this?
HTML
<ul id="navigation">
<li><a id="1" href="#">Link 1</a></li>
<li><a id="2" href="#">Link 2</a></li>
<li><a id="3" href="#">Link 3</a></li>
</ul>
<div class="box">
<img src="default.jpg"/>
</div>
JQuery
$(document).ready(function() {
$('#navigation li a#1').hover(
function(){
$(this).addClass('hover');
$('.box img').attr('src', 'image1.jpg');
},
function(){
$(this).removeClass('hover');
$('.box img').attr('src', 'default.jpg');
}
);
$('#navigation li a#2').hover(
function(){
$(this).addClass('hover');
$('.box img').attr('src', 'image2.jpg');
},
function(){
$(this).removeClass('hover');
$('.box img').attr('src', 'default.jpg');
}
);
$('#navigation li a#3').hover(
function(){
$(this).addClass('hover');
$('.box img').attr('src', 'image3.jpg');
},
function(){
$(this).removeClass('hover');
$('.box img').attr('src', 'default.jpg');
}
);
});