I have been working on improving my coding skills by learning jQuery. One of the tasks I tackled was creating a simple image showcase. However, the code I ended up with seems lengthy and not very efficient. Can anyone provide suggestions on how to enhance this?
HTML:
<div id="gallery">
<div style="float: left; border: 1px solid red; width: 600px; height: 450px;background-image: url(images/main_image.png);" class="big_image"></div>
<div style="float:left;" id="thumbnails">
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/thumbnail_1.png);" class="thumbnail_1"></div>
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/thumbnail_2.png);" class="thumbnail_2"></div>
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/thumbnail_3.png);" class="thumbnail_3"></div>
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/main_thumbnail.png);" class="main_thumbnail"></div>
</div>
</div>
JS
<script type="text/javascript">
$(function(){
$(".thumbnail_1").click(function(){
$(".big_image").css("background-image","url('images/image_1.png')");
});
});
$(function(){
$(".thumbnail_2").click(function(){
$(".big_image").css("background-image","url('images/image_2.png')");
});
});
$(function(){
$(".thumbnail_3").click(function(){
$(".big_image").css("background-image","url('images/image_3.png')");
});
});
$(function(){
$(".main_thumbnail").click(function(){
$(".big_image").css("background-image","url('images/main_image.png')");
});
});
</script>