Ok, so I have a list of about 5 links, one after another. When I hover over one of these links, I need it to expand in size (to distinguish it from the others). And when I click on one of these links, I want it to update the image within a different element. I have figured out how to do this for a singular link using JQuery and CSS, but I am wondering if I need to create 4 additional (for the 4 other links) sets of JQuery functions, or if there is a way to conserve codespace by using for loops with a counter of sorts. My issue with the logic (of using just one all-encompassing function) stems from the fact that I do not know how to distinguish between links once they are hovered over. This makes me think I need a different set of functions for each link. Any and all advice is sincerely appreciated.
Here is my HTML code:
<div class="interestsMarquee">
<img src="sportsInterest.png" class="trigger" id="interest1" alt="sports" />
<img src="sportsInterest.png" class="trigger" id="interest2" alt="music" />
<img src="sportsInterest.png" class="trigger" id="interest3" alt="hunting" />
<img src="sportsInterest.png" class="trigger" id="interest4" alt="exercise" />
<img src="sportsInterest.png" class="trigger" id="interest5" alt="shopping" />
</div>
Here is my JQuery code:
<script>
$(function() {
var i = '1';
$("#interest"+i).hover(function()
{
$("#interest"+i).css("width","115%")
.css("height","70px")
.css("margin-left","-10px");
},function()
{
$("#interest"+i).css("width","95%")
.css("height","56px")
.css("margin-left","3px");
});
$('.trigger').css('cursor', 'pointer')
.click({id: 'myImage'}, changeImage);
function changeImage(e)
{
var element=document.getElementById(e.data.id)
if (element.src.match("images/Cowboys.jpg"))
{
element.src="images/Countryside_bg.jpg";
}
else
{
element.src="images/Cowboys.jpg";
}
}
});
</script>